Jump to content

pagination


andy_b_1502

Recommended Posts

<?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?

 

Link to comment
Share on other sites

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:

 

:shrug:

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.