mcfmullen Posted November 27, 2010 Share Posted November 27, 2010 So this is the pagination code I am trying to use: <?php include("variables.php"); if (!(isset($pagenum))) { $pagenum = 1; } $data = mysql_query("SELECT * FROM $itemspec"); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM $itemspec .$max"); ?> <?php while($row = mysql_fetch_array( $data_p )){ // output of query// } While in theory it should work, I get this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\items.php on line 115 With line 115 being while($row = mysql_fetch_array( $data_p )){ However, If i edit $data_p = mysql_query("SELECT * FROM $itemspec .$max"); to: $data_p = mysql_query("SELECT * FROM $itemspec LIMIT 0,10"); the code works fine. Can anyone figure out what my problem is because nothing I do seems to work! Quote Link to comment https://forums.phpfreaks.com/topic/220022-pagination-fail-boolean/ Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2010 Share Posted November 27, 2010 Your query execution is failing and returning a boolean false. Separate the query string from the query execution, and echo it along with any errors returned by mysql_error() $query = "SELECT whatever"; $data_p = mysql_query($query) or die( "<br>Query string $query<br>Returned errors: " . mysql_error() ); Quote Link to comment https://forums.phpfreaks.com/topic/220022-pagination-fail-boolean/#findComment-1140444 Share on other sites More sharing options...
mcfmullen Posted November 28, 2010 Author Share Posted November 28, 2010 Upon executing your solution I discovered the problem. The . between the variables was being sent as a . instead of concatinating the variables. I removed the . and everything is working fine. Thank you for your help! Quote Link to comment https://forums.phpfreaks.com/topic/220022-pagination-fail-boolean/#findComment-1140589 Share on other sites More sharing options...
Pikachu2000 Posted November 28, 2010 Share Posted November 28, 2010 Very good. Just be aware that sending the query string and errors to the screen is for development, and on a live, production site, they should be logged instead, with a generic error message sent to the screen like "Sorry, there was a database problem" so as not to give up too much information. Quote Link to comment https://forums.phpfreaks.com/topic/220022-pagination-fail-boolean/#findComment-1140591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.