blink359 Posted December 22, 2010 Share Posted December 22, 2010 Hi im trying to get pagination to work this is something im very new to and have tried a load f tutorial scripts but i keep getting: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a1581845/public_html/publist.php on line 60 here is my php code: <html> <head> <link rel="stylesheet" href="css/reset.css"> <link rel="stylesheet" href="css/style.css"> <title>E-Beer - Buying your pint has never been so easy!</title> </head> <body> <div id="head"><div id="header"> <div id="logo"></div><div id="login"> <form action="#" method="post"> <h3>Login to website:</h3> Username: <input type="text" name="name" class="1pxtotheright"><br> Password: <input type="password" name="password" class="1pxtotheright"><br> <div class="smallprint"><a href="register.php">Register Now</a> <a href="forget.php">Forgot Your Password?</a> </div> <input type="submit" value="Login"> </form> </div> </div> <div id="navbar"><a href="#">Home</a> <a href="#">Find a Pub</a> <a href="#">Register</a> <a href="#">Add your Pub</a> <a href="#">Contact Us</a> <a href="#">About Us</a></div> </div> <div id="container"> <?php include('includes/mysql.php'); $max = 1; //amount of articles per page. change to what to want $p = $_GET['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view the news article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM data WHERE id = '$id'"); while($info = mysql_fetch_array($sql)) { echo ' information'; } }else{ //view all the news articles in rows $sql = mysql_query("SELECT * FROM data LIMIT ".$limits.",$max"); //the total rows in the table $totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM Pubs"),0); //the total number of pages (calculated result), math stuff... $totalpages = ceil($totalres / $max); //the table echo "<table><tr><td>Title</td><td>Author</td></tr><tr>"; while($info = mysql_fetch_array($sql)) { echo ' information } //close up the table echo " </tr></table>"; for($i = 1; $i <= $totalpages; $i++){ //this is the pagination link echo'<a href="publist.php?p='. $i .'">'. $i .'</a>'; } } ?> </div> </body> </html> If anyone could help it will be great, Thanks, Blink359 Quote Link to comment https://forums.phpfreaks.com/topic/222429-problems-with-pagination/ Share on other sites More sharing options...
BlueSkyIS Posted December 22, 2010 Share Posted December 22, 2010 i suggest that you expand the code that does database interaction, and check for errors after executing SQL, so it is easier to figure out what's wrong. example: $sql = "SELECT * FROM sometable"; $result = mysql_query($sql) or die(mysql_error(). " IN $sql"); while ($an_array = mysql_fetch_array($result)) { // etc.... the problem is probably that a SQL query is failing, but the code doesn't check to see if the SQL is failing, so you get the error you posted. Quote Link to comment https://forums.phpfreaks.com/topic/222429-problems-with-pagination/#findComment-1150520 Share on other sites More sharing options...
blink359 Posted December 22, 2010 Author Share Posted December 22, 2010 Ah thanks for that, found the problem Blink359 Quote Link to comment https://forums.phpfreaks.com/topic/222429-problems-with-pagination/#findComment-1150524 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.