Monk3h Posted August 26, 2009 Share Posted August 26, 2009 This script returns info from my database and limits it to a certain amount of items per page, then it adds links to view more pages etc.. also know as pagition. My problem is that i have an error. Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/monk3h/public_html/WMM/minishop/page.php on line 36 Line 36: while($line = mysql_fetch_array( $qresult )) Full code: <?php include ("config.php"); $pages=$_GET['page']; //Get the current page // This the full code which will generate a paging system $limit=2; // Limit of result per page $qresult = mysql_query("SELECT * FROM items"); // Let's get the query $nrResults=mysql_num_rows($qresult); // Count the results if (($nrResults%$limit)<>0) { $pmax=floor($nrResults/$limit)+1; // Divide to total result by the number of query you want // to display per page($limit) and create a Max page } else { $pmax=floor($nrResults/$limit); } $qresult = mysql_query("SELECT * FROM items DESC LIMIT ".(($_GET["page"]-1)*$limit).", $limit"); //Need to generate query considering your limit while($line = mysql_fetch_array( $qresult )) // LINE 36 ####################### { // Now once we got the query from MySQL, we need to think what we to do it. You can do anything. This is just an example echo " Name: ".$line['id']." <br /> Age: ".$line['name']." <br /> Phone Number: ".$line['image']." <br /> "; // Here comes the Real part of this Tutorial!! } echo "<div class='navpage'>"; // Make a simple css // We need to create a Previous page, so we need $pages to be bigger than 1, otherwise at the first page we would get a 0. //For the previous to show up we need at least to be at the second page. if($pages > 1) { $prevp="<a href='http://www.riseofkingdoms.net/WMM/minishop/page.php?page=".($pages-1)."' title='Previous Page'>Previous Page</a>"; } else {echo "";} echo $prevp; // Here We want create a page from the results we got by dividing the total by the the limit. So let say you got //45 results and you want 5 results per page; these simple lines will create you 8 pages. $pid=1; while ($pid<=$pmax) { $paging= "<a href='http://www.riseofkingdoms.net/WMM/minishop/page.php?page=$pid' title='Page $pid of $pmax'> $pid</a>"; //So here, let say we are at the 3rd page and we want the 3 to be blank so the user can know where is he now. //This will act as Current Page! We need to replace the url by a text $newpaging=str_replace("<a href='http://www.riseofkingdoms.net/WMM/minishop/page.php?page=$pages' title='Page $pages of $pmax'> $pages</a>", "<span>$pages</span>", $paging); echo $newpaging; $pid++; // create pages until reach the result } //We want to create a next page and a last page, $pages have to be less than $pmax. if($pages < $pmax) { $nextp="<a href='http://www.riseofkingdoms.net/WMM/minishop/page.php?page=".($pages+1)."' title='Next Page'>Next Page</a>"; } else {echo "";} echo $nextp; echo "<a href='http://www.riseofkingdoms.net/WMM/minishop/page.php?page=$pmax' title='Last Page'>Last Page</a>"; echo "</div>"; ?> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/ Share on other sites More sharing options...
Maq Posted August 26, 2009 Share Posted August 26, 2009 Most likely your query is failing. Echo out the mysql_error() or the query string to see what's actually going on. Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/#findComment-906994 Share on other sites More sharing options...
ignace Posted August 26, 2009 Share Posted August 26, 2009 SELECT * FROM items DESC LIMIT should be: SELECT * FROM items LIMIT Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/#findComment-907015 Share on other sites More sharing options...
Monk3h Posted August 26, 2009 Author Share Posted August 26, 2009 Thnaks to you both. Problem sorted! Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/#findComment-907035 Share on other sites More sharing options...
Maq Posted August 26, 2009 Share Posted August 26, 2009 SELECT * FROM items DESC LIMIT should be: SELECT * FROM items LIMIT Totally didn't even see that... If you want to order in descending order then you need to keep that clause in there but specify what to order by. ORDER BY [column_name] DESC LIMIT Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/#findComment-907060 Share on other sites More sharing options...
ignace Posted August 27, 2009 Share Posted August 27, 2009 Totally didn't even see that... That's odd with OP's so well-formed and properly indented code? Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/#findComment-907358 Share on other sites More sharing options...
Maq Posted August 27, 2009 Share Posted August 27, 2009 Totally didn't even see that... That's odd with OP's so well-formed and properly indented code? lol. Hopefully that was caused by a copy and paste or something... Quote Link to comment https://forums.phpfreaks.com/topic/172013-page-numbering/#findComment-907514 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.