beginning pagination

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

beginning pagination

Post by manRay »

I need to use some form of pagination to sort through some user records. Client side pagination will not work due to the way I have my site set up. I have found a tutorial for server side pagination at http://articles.sitepoint.com/article/p ... pagination. I believe I have the right setup, but obviously not. The table does not get filled in properly. Hope someone could shed some light on this topic. Thanks in advanced!

My code

Code: Select all

<?php

$email = $_SESSION["email"];

$connection = mysql_connect("*********","*******","******");

//try to connect to database
if ($connection) {
	mysql_select_db("******", $connection);
	$get_num = mysql_fetch_row(mysql_query("SELECT * FROM accounts WHERE email = '$email'"));
	$num = $get_num[0];
	$query = mysql_query("SELECT * FROM support WHERE customer='$num'");
	$num_rows = mysql_num_rows($query);
	
	if ($num_rows > 0) {
		
		require_once "Paginated.php";
		require_once "TableLayout.php";	
		
		$requests = array();
	
		$i = 0;
		while($fields = mysql_fetch_row($query)) {
			$requests[i] = $fields;
			$i++;
		}
		
		$pagedResults = new Paginated($requests, 3, 1);
		
		echo "<table id='pageme'><thead><tr><th align='center'>Request #</th><th align='center'>Date</th><th align='center'>Subject</th><th align='center'>Status</th></tr></thead><tbody>";
		
		while($row = $pagedResults->fetchPagedRow()) { 
 			echo "<tr><td align='center'>$row[0]</td><td>$row[1]</td><td>$row[3]</td><td>$row[5]</td></tr>";
		} 
		
		$pagedResults->setLayout(new TableLayout());
		
		echo "</tbody><tfoot>$pagedResults->fetchPagedNavigation()</tfoot></table>";
	}
	
	else {
		
		echo "<table border='1' style='border-collapse:collapse'><thead><tr><th align='center'>Request #</th><th align='center'>Date</th><th align='center'>Subject</th><th align='center'>Status</th></tr></thead>";


		echo "<tbody><tr><td colspan='5'>You have not yet submited a request.</td></tr></tbody>";
		echo "</table>";
		
	}
	
}

else {
	die("Not Connected: " . mysql_error());	
}

mysql_close($connection);
?>
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

Re: beginning pagination

Post by manRay »

I decided to go with some a little less complicated and followed a video tutorial at http://www.youtube.com/watch?v=wC0uc_TkdR0 The problem now is getting the array of rows.

Error:Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/s/l/i/*********/html/php/widgets.php on line 41

line 41:

Code: Select all

while($row = mysql_fetch_row($get)) { 
 			echo "<tr><td align='center'>$row[0]</td><td>$row[1]</td><td>$row[3]</td><td>$row[5]</td></tr>";
		} 
$get =

Code: Select all

$get = mysql_query("SELECT * FROM support WHERE customer='$num' LIMIT $start,$perpage");
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: beginning pagination

Post by Jade »

You probably have a problem with your page number vars. You can try printing out your SQL or doing this:

Code: Select all

$get  = mysql_query("SELECT * FROM support WHERE customer='$num' LIMIT $start,$perpage") or die ('There was an error: ' . mysql_error());
Post Reply