4 Replies - 490 Views - Last Post: 24 February 2013 - 01:30 PM Rate Topic: -----

#1 DkSnowdon  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 31-October 12

adding a image gallery to my website

Posted 23 February 2013 - 06:24 PM

i have found a image gallery on the internet that allows other to use as long as the source code keeps the copyright stuf, the htl is quite simple and all the css that is complicated but i am having a program using mysqli with it, i havent used mysqli much and i have never done and object object orientated php

here is my attempted to make the image gallery dynamic and gets its categories and images from a data base

<?php require "ws_e/db_connect.php"; ?>

<div class="photo">
<ul class="topic">

<?
// loop though categorys
$query = "SELECT * FROM category ORDER BY order";
$result = $mysqli->query($query);
while($row = $result->fetch_array(MYSQLI_ASSOC))
{
	
	// get id
	$id = $row['id'];
?>
	<li><a class="set" href="#Portraits"><? echo $row['name'];?><!--[if gte IE 7]><!--></a><!--<![endif]-->
	<!--[if lte IE 6]><table><tr><td><![endif]-->
		<ul>
<?
// loop though images
$_imagequery = "SELECT * FROM image WHERE categoryID = '$id' ORDER BY order";
$image_result = $mysqli->query($image_query);
while($image_row = $image_result->fetch_array(MYSQLI_ASSOC))
{
?>
			<li><a href="lbox/portrait1.jpg"><img src="images/<? echo $image_row['extension']; ?>" alt="" title="" /></a></li>
<? } ?>
		</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]-->
	</li>
    
<? } ?>
<br class="clear" />
</div>




my problem is this error
Fatal error: Call to a member function fetch_array() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/ksnowdonV2/lightbox.php on line 10



the gallery i am trying to add is located at http://www.cssplay.c...ox.html#flower8

any help greatly appreciated
thanks dale

my db_connect is
<?

$mysqli = new mysqli("localhost", "root", "", "ksnowdonv3");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
?>


Is This A Good Question/Topic? 0
  • +

Replies To: adding a image gallery to my website

#2 DkSnowdon  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 31-October 12

Re: adding a image gallery to my website

Posted 23 February 2013 - 10:47 PM

can i change my question can anyone help me write this code in a Procedural style?
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: adding a image gallery to my website

Posted 24 February 2013 - 01:51 AM

View PostDkSnowdon, on 24 February 2013 - 06:47 AM, said:

can i change my question can anyone help me write this code in a Procedural style?

that wouldn’t change anything. at most you would replace the word "object" by "resource".

with regards to the error message, try to grasp what it is telling you:

Quote

Call to a member function fetch_array() on a non-object

so you have a variable that you treat as object, but that isn’t. so, which variable could that be? where does it come from?
Was This Post Helpful? 0
  • +
  • -

#4 DkSnowdon  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 31-October 12

Re: adding a image gallery to my website

Posted 24 February 2013 - 03:06 AM

i have n clue to what that means
Was This Post Helpful? 0
  • +
  • -

#5 Sho Ke  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 110
  • View blog
  • Posts: 250
  • Joined: 13-October 11

Re: adding a image gallery to my website

Posted 24 February 2013 - 01:30 PM

$result = $mysqli->query($query);


Here, you call the query method of $mysqli .

Taken from the manual:

Quote

Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.


On line 10, you're assuming the query was successful(that the query is returning a mysqli_result object). The error plainly states that you tried using a member method on a non-object. The only thing that line 9 could make $result be, other than a mysqli_result object, is a boolean. Your query is failing.

The manual is your best friend when you're coding. Always, always, always use it! If you're getting an error, read the manual entries over all methods you used near the line the error occurred. Read the parameters it takes in. Read the notes, and most importantly, read the return values! If you aren't absolutely sure what type a variable is, var_dump it!

This post has been edited by Sho Ke: 24 February 2013 - 01:35 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1