andy_b_1502 Posted June 30, 2012 Share Posted June 30, 2012 <?PHP session_start(); include ('php only scripts/db.php'); error_reporting(E_ALL); ini_set("display_errors", 1); $what_services = "R"; $approved = "approved"; //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM companies WHERE what_services IN('R','B') ORDER BY approved DESC, company_name ASC") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 4; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; while ( $row = mysql_fetch_array($result)) { $approved = $row['approved']; $what_services = $row['what_services']; SWITCH ($approved) { case 0: break; case 1: ?> <?PHP echo $row['company_name']; ?></p> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> </figure> <?PHP echo $row['company_name']; ?> <?PHP break; case 2: ?> <?PHP echo $row['company_name']; ?> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] ?> <img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/> <?PHP break; case 3: ?> <a href="view00.php?id=<?PHP echo $row['id']; ?>"><?PHP echo $row['company_name']; ?></a> <a href="view00.php?id=<?PHP echo $row['id']; ?>"> <?PHP echo $row['street1'] . "<br>" . $row['street2'] . "<br>" . $row['city'] . "," . $row['postcode'] . "<br>phone: " . $row['phone'] . "<br>mobile/other: " . $row['phone'] ?></a> click logo to read more...<a href="view00.php?id=<?PHP echo $row['id']; ?>"><img src="images/thumbs/<?PHP echo $row['upload']; ?>" alt="logo"/></a> <?PHP break; } } ?> The im getting the error: "Notice: Undefined variable: result in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 68 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 68" But i define it here $what_services = "R"; $approved = "approved"; could someone please help me to define it properly or help with the correct way to do this please? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2012 Share Posted June 30, 2012 http://aspektas.com/blog/really-simple-php-pagination/ Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted June 30, 2012 Author Share Posted June 30, 2012 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 12 Warning: implode() [function.implode]: Argument must be an array in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 12 Pages: Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted June 30, 2012 Share Posted June 30, 2012 can you supply code please Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 30, 2012 Share Posted June 30, 2012 Are you really looking at the errors? I'll go back to the first code you posted. You received these two errors: Notice: Undefined variable: result in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 68 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 68 This is line 68 while ( $row = mysql_fetch_array($result)) { And you say: But i define it here $what_services = "R"; $approved = "approved"; The error was about the variable $result not being defined - that caused both errors. You assigned the DB results to a different variable and used the wrong one in that line. Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 1, 2012 Author Share Posted July 1, 2012 just so i'm getting it right, it should be: $row = "approved"; to define? if so i'm getting error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 12 Warning: implode() [function.implode]: Argument must be an array in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 12 Pages: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosoraweb023/b109/ipg.removalspacecom/test2.php on line 29 ?> i have an array? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 1, 2012 Share Posted July 1, 2012 if you listened the exact problem you are having is $result is not defined ANYWHERE! Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 2, 2012 Author Share Posted July 2, 2012 $result = mysql_query($query); whats that then? Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 2, 2012 Author Share Posted July 2, 2012 http://www.removalspace.com/removals.php?pn=-1 this i after i added: $result = mysql_query($sql2); How do i get it to display 10 items per page and at least show more than 1 result all together?? Quote Link to comment Share on other sites More sharing options...
andy_b_1502 Posted July 3, 2012 Author Share Posted July 3, 2012 i don't understand why the display area with the buttons for the user to choose which page has got a 0 and a -1 This bit of code should keep it at page 1 shouldn't it: if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } does anybody know why this is happening? Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 3, 2012 Share Posted July 3, 2012 i don't understand why the display area with the buttons for the user to choose which page has got a 0 and a -1 This bit of code should keep it at page 1 shouldn't it: if($pn < 1){ $pn = 1; }else if($pn > $lastPage){ $pn = $lastPage; } does anybody know why this is happening? Thanks From what you've provided? No. Just because you have a block of code to force a variable to be no less than one and no more than $lastPage doesn't tell us anything about where you may be using those variables elsewhere on the page. Or, you might not even be using those variables for all we know - which was your first problem in this thread. In fact, this isn't even the issue you first started int his thread. You don't get your own dedicated thread to work through many different problems. Once a problem is resolved, mark the thread as solved and open a new thread for new problems. Quote Link to comment 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.