dazzclub Posted June 27, 2008 Share Posted June 27, 2008 Hi guys, I'm working on a pagination script, and when i test it, its throwing up to warnings. 1)Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\darrensPAINT\admin\view_user.php on line 75 2)Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\darrensPAINT\admin\view_user.php on line 99 I originally thought it may have been the query i wrote, but ive looked at the that and it seems fine, but i feel a fresh pair of eyes would do the trick.. Heres the script im working on <?php //number of records to show per page $display = 10; //determin how many pages there are.. if(isset($_GET['p']) && is_numeric($_GET ['p'])){//already been determined $pages = $_GET['p']; }else{ //no need to determine //count number of rows $query = "SELECT COUNT(user_id) FROM users"; $return = @mysqli_query($connection, $query); $row = @mysqli_fetch_array($return, MYSQLI_NUM); $records = $row[0]; //calculate the number of pages if ($records > $display){ //more than one page $pages = ceil ($records/$display); }else{ $pages = 1; } }//end of p IF //determine where in the database to start returning results... if(isset($_GET['s']) && is_numeric ($_GET['s'])){ $start = $_GET['s']; }else{ $start = 0; } //make the query $query = "SELECT surname, firstname, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr, user_id FROM users ORDER_BY registration_date ASC LIMIT $start, $display"; $return = @mysqli_query($connection,$query); //table header echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left">EDIT</td> <td align="left">DELETE</td> <td align="left">Surname</td> <td align="left">Firstname</td> <td align="left">Date registered</td> </tr>'; //fecth and print all the records $bg ='#eeeeee';// set the initial background colour. while($row = mysqli_fetch_array($return, MYSQLI_ASSOC)){ $bg =($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');//switch the background colour echo '<tr bgcolor="'.$bg.'"> <td align="left"><a href="edit_user.php?id='. $row['user_id'].'">EDIT</a></td> <td align="left"><a href="delete_user. php?id='.$row['user_id'].'">DELETE </a></td> <td align="left">'.$row['surname'].'</td> <td align="left">'.$row['firstname'].'</td> <td align="left">'.$row['dr'].'</td> </tr> '; }//end of while loop echo '</table>'; mysqli_free_result($return); mysqli_close($connection); //make the links to other page if neccessary if($pages>1){ //add some spacing and start a paragraph echo '<br /><p>'; //determine what page the script is on $current_page = ($start/$display)+1; //if its not the first page, make a previous button if($current_page!=1){ echo '<a href="view_users.php?s=' . ($start - $display). '&p='.$pages. '">previous</a>'; } //make all the numbered pages; for($i = 1; $i <= $pages; $i++){ if($i !=$current_page){ echo '<a href="view_users.php?s='. (($display*($i-1))).'&p='. $pages. '">' .$i.'</a>'; }else{ echo $i.''; } }//end of for loop //if its not the last page, make a next button if($current_page != $pages){ echo'<a href="view_users.php?s='. ($start + $display) . '&p=' .$pages. '">Next</a>'; } echo '</p>' ;//close the paragraph. }//end of links section ?> i have picked out the actual line with numbers above and below $bg ='#eeeeee';// set the initial background colour. line 75 while($row = mysqli_fetch_array($return, MYSQLI_ASSOC)){ $bg =($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');//switch the background colour and }//end of while loop echo '</table>'; line 99 mysqli_free_result($return); mysqli_close($connection); //make the links to other page if neccessary if($pages>1){ any help would be great! Cheers Darren Link to comment https://forums.phpfreaks.com/topic/112239-warningboolean-givin/ Share on other sites More sharing options...
pojr Posted June 27, 2008 Share Posted June 27, 2008 I think it has to do with the format you have. Try echo "Stuff"; rather then echo 'stuff';. Link to comment https://forums.phpfreaks.com/topic/112239-warningboolean-givin/#findComment-576274 Share on other sites More sharing options...
discomatt Posted June 27, 2008 Share Posted June 27, 2008 No, it means your query returned FALSE, and not actual data. $return = @mysqli_query($connection, $query); if (!$return) exit('Query failed!'); or if ( ($return = @mysqli_query($connection, $query)) == FALSE ) exit('Query failed!'); As a second note, I'd avoid using the '@' error suppressor until your script goes live. Link to comment https://forums.phpfreaks.com/topic/112239-warningboolean-givin/#findComment-576278 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.