Jump to content

Problems with pagination


blink359

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.