Jump to content

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean..


5kyy8lu3

Recommended Posts

Hi.  I keep getting this stupid error.  It's happened to me on several occasions and I'd like to get an answer on what I'm doing wrong so I can put an end to this annoying error.  Here's the code, it's for my pictures pagination:

 

$query = "SELECT * FROM " . $_SESSION['logname'] . "_data";
$result = mysqli_query($cxn, $query);
$num_rows = mysqli_num_rows($result);     //This checks to see total number of pics in the table

$curpic = explode(".", $_GET['pic']);   // pulls the number off of the filename so it can be compared
if ( $curpic['0'] > 1 )                      //Checks to see if it's first pic (if it is, it doesn't give a link for "previous picture")

{
	$query2 = 'SELECT filename FROM ' . $_SESSION['logname'] . '_data WHERE filename < ' . $_GET['pic'] . ' LIMIT 1';
	$result2 = mysqli_query($cxn, $query2);
	$nextpage = mysqli_fetch_assoc($result2);
	echo '<a href="pic.php?pic=' . $nextpage['filename'] . '">Previous Picture</a> - ';
}

else

{
	echo '<font color="gray"><i>Previous Picture</i></font> - ';
}

 

$_SESSION['logname'] is the username, that plus the _data is the name of the table the picture data is in

 

$_GET['pic'] is the filename of the current picture (example: pic.php?pic=12.jpg)

 

any ideas? thanks

 

oh and here's the full error:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /hermes/bosweb/web191/b1913/ipw.kloudzco/public_html/pic.php on line 114
Link to comment
Share on other sites

check for errors in your SQL by changing your code to:

 

$query = "SELECT * FROM " . $_SESSION['logname'] . "_data";
$result = mysqli_query($cxn, $query) or die(mysqli_error($cnx));
$num_rows = mysqli_num_rows($result);     //This checks to see total number of pics in the table

$curpic = explode(".", $_GET['pic']);   // pulls the number off of the filename so it can be compared
if ( $curpic['0'] > 1 )                      //Checks to see if it's first pic (if it is, it doesn't give a link for "previous picture")

   {
      $query2 = 'SELECT filename FROM ' . $_SESSION['logname'] . '_data WHERE filename < ' . $_GET['pic'] . ' LIMIT 1';
      $result2 = mysqli_query($cxn, $query2) or die(mysqli_error($cnx));
      $nextpage = mysqli_fetch_assoc($result2);
      echo '<a href="pic.php?pic=' . $nextpage['filename'] . '">Previous Picture</a> - ';
   }

else

   {
      echo '<font color="gray"><i>Previous Picture</i></font> - ';
   }

Link to comment
Share on other sites

oops...you use cxn not cnx:

 

$query = "SELECT * FROM " . $_SESSION['logname'] . "_data";
$result = mysqli_query($cxn, $query) or die(mysqli_error($cxn));
$num_rows = mysqli_num_rows($result);     //This checks to see total number of pics in the table

$curpic = explode(".", $_GET['pic']);   // pulls the number off of the filename so it can be compared
if ( $curpic['0'] > 1 )                      //Checks to see if it's first pic (if it is, it doesn't give a link for "previous picture")

   {
      $query2 = 'SELECT filename FROM ' . $_SESSION['logname'] . '_data WHERE filename < ' . $_GET['pic'] . ' LIMIT 1';
      $result2 = mysqli_query($cxn, $query2) or die(mysqli_error($cxn));
      $nextpage = mysqli_fetch_assoc($result2);
      echo '<a href="pic.php?pic=' . $nextpage['filename'] . '">Previous Picture</a> - ';
   }

else

   {
      echo '<font color="gray"><i>Previous Picture</i></font> - ';
   }

Link to comment
Share on other sites

oops...you use cxn not cnx:

 

well it turns out I should've added quotes around the string i was comparing it to, so it was an sql error, appreciate the help

 

now my next problem, my pagination works fine moving up one picture but the link to go down one picture always shows 1.jpg for the link, any ideas? lol the code is the same as the one I posted in my original post only i had a less than sign for the comparison

 

i'm guessing it just finds the very first one in the table "1.jpg" being meeting the comparison criteria so it uses that, but I need the one just before the one i'm on, know how to do this? i'm lost lol

 

UPDATE: oh and if I'm at 1 and hit next, i goes to 10, and if i'm at 2 and hit next, it goes to 20 lol, i obviously need a better algorithm, i had it working fine until i changed stuff around to offset being able to delete a picture and having the pagination work fluidly around it

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.