Jump to content

Pagination.. only first line of data shows


jaxdevil

Recommended Posts

I have a pagination code that works on one site, but I changed the database fields it is pulling for this site I copied it to and it is not working. It is made to display 25 rows, then paginate. Well it works fine on one site, then I change ONLY the connection setting and the rows it is pulling from the database and it then will display the first rows data, it pulls 25 rows, it is in a table and creates the table with all 25 rows, but only populates the first one with data. Anyone have an idea on this one? I put the one I am using below. That is the one that is not working, below that I copied the code I am using on the site that IS working.

 

<?php
require( $_SERVER['DOCUMENT_ROOT']."/configs/connection.php");
?>
<?php
if ( $action== "List" ) {
// Select total results for pagination
$result = mysql_query("SELECT count(*) FROM prod WHERE `mod` LIKE '%'") or die(mysql_error());
$num_records = mysql_result($result,0,0);

// Set maximum number of rows and columns
$max_num_rows = 25;
$max_num_columns = 1;
$per_page = $max_num_columns * $max_num_rows;

// Work out how many pages there are
$total_pages = ceil($num_records / $per_page);

// Get the current page number
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1;

// Work out the limit offset
$start = ($page - 1) * $per_page;

// Select the results we want including limit and offset
$result = mysql_query("SELECT `mod` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$cat = mysql_query("SELECT `cat` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$sub = mysql_query("SELECT `sub` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$man = mysql_query("SELECT `man` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$mod = mysql_query("SELECT `mod` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$descrip = mysql_query("SELECT `descrip` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$pri = mysql_query("SELECT `pri` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$lea = mysql_query("SELECT `lea` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$star = mysql_query("SELECT `star` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$star_pri = mysql_query("SELECT `star_pri` FROM prod LIMIT $start, $per_page") or die(mysql_error());
$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);
$num_rows = ceil(mysql_num_rows($result)/$num_columns);
// Echo the results
?>
<table width="500" border="1" bordercolor="black" cellpadding="0" cellspacing="0" style="border-left-width:0px; border-top-width: 1px; border-bottom-width: 0px; border-right-width: 0px;">
<tr width="500">
<td width="40">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Export</font></b>
</td>
<td width="25">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Delete</font></b>
</td>
<td width="25">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Edit</font></b>
</td>
<td width="160">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Model</font></b>
</td>
<td width="250">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Description</font></b>
</td>
<td width="50">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Price</font></b>
</td>
</tr>
<?
for ($r = 0; $r < $max_num_rows; $r++){
echo "<tr width=\"500\" height=\"5\">\n";
for ($c = 0; $c < $max_num_columns; $c++){ // 1
	$x = $r * $max_num_columns + $c;
	if ($x < mysql_num_rows($result)){
				$cat = mysql_result($cat, $x, 0);
				$sub = mysql_result($sub, $x, 0);
				$man = mysql_result($man, $x, 0);
                     $mod = mysql_result($mod, $x, 0);
                     $descrip = mysql_result($descrip, $x, 0);
                     $pri = mysql_result($pri, $x, 0);
                     $lea = mysql_result($lea, $x, 0);
                     $star = mysql_result($star, $x, 0);
                     $star_pri = mysql_result($star_pri, $x, 0);
                   $y = <<<HTML
<td width="40" align="center" valign="middle">
<a href="ebay_generator.php?mod={$mod}" target="_blank"><img src="images/ebaybutton.gif" border="0"></a>
</td>
<form action="inventory.php">
<td width="25" valign="middle">
<center>
<font face="Tahoma,Verdana,Arial" size="0.80em">
<input type="hidden" name="action" value="Remove">
<input type="hidden" name="cat" value="{$cat}">
<input type="hidden" name="sub" value="{$sub}">
<input type="hidden" name="man" value="{$man}">
<input type="hidden" name="mod" value="{$mod}">
<input type="hidden" name="oldmod" value="{$mod}">
<input type="hidden" name="descrip" value="{$descrip}">
<input type="hidden" name="pri" value="{$pri}">
<input type="hidden" name="lea" value="{$lea}">
<input type="hidden" name="star" value="{$star}">
<input type="hidden" name="star_pri" value="{$star_pri}">
<input type="image" src="images/drop.gif" border="0"></font>
</center>
</td>
</form>
<form action="" method="post">
<td width="25" valign="middle">
<center>
<font face="Tahoma,Verdana,Arial" size="0.80em">
<input type="hidden" name="action" value="Edit">
<input type="hidden" name="cat" value="{$cat}">
<input type="hidden" name="sub" value="{$sub}">
<input type="hidden" name="man" value="{$man}">
<input type="hidden" name="mod" value="{$mod}">
<input type="hidden" name="oldmod" value="{$mod}">
<input type="hidden" name="descrip" value="{$descrip}">
<input type="hidden" name="pri" value="{$pri}">
<input type="hidden" name="lea" value="{$lea}">
<input type="hidden" name="star" value="{$star}">
<input type="hidden" name="star_pri" value="{$star_pri}">
<input type="image" src="images/edit.gif" border="0"></font>
</center>
</td>
</form>
<td width="160">
<font face="Tahoma,Verdana,Arial" size="0.80em">{$mod}</font>
</td>
<td width="250">
<font face="Tahoma,Verdana,Arial" size="0.80em">{$descrip}</font>
</td>
<td width="50">
<font face="Tahoma,Verdana,Arial" size="0.80em">{$pri}</font>
</td>
HTML;

                }
                else {
                   $y = '';
                }
	echo "$y";
}
echo "</tr>\n";
}

// Echo page numbers
echo "</table></center><center>\n";
echo "<table width=480 cellspacing=0 cellpadding=0 border=0><tr><td><font face=\"Tahoma,Verdana,Arial\" size=0.50em><center>Go to: ";
// Echo the results
for ($i=1;$i <= $total_pages;$i++) {
if ($i == $page) echo " $i "; else echo " <a href=\"?action=List&page=$i\">$i</a> ";}
?>
</font></center></td></tr></table>
</div>
</font>
</div>
<br>
<?
}
?>

 

Now here is the code that DOES work:

 

<?php
require( $_SERVER['DOCUMENT_ROOT']."/configs/connection.php");
?>
<?php
if ( $action== "List" ) {
// Select total results for pagination
$result = mysql_query("SELECT count(*) FROM products WHERE `active`='Yes'") or die(mysql_error());
$num_records = mysql_result($result,0,0);

// Set maximum number of rows and columns
$max_num_rows = 25;
$max_num_columns = 1;
$per_page = $max_num_columns * $max_num_rows;

// Work out how many pages there are
$total_pages = ceil($num_records / $per_page);

// Get the current page number
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1;

// Work out the limit offset
$start = ($page - 1) * $per_page;

// Select the results we want including limit and offset
$result = mysql_query("SELECT `mod` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$cat = mysql_query("SELECT `cat` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$subcat = mysql_query("SELECT `subcat` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$man = mysql_query("SELECT `man` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$maker = mysql_query("SELECT `man` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$mod = mysql_query("SELECT `mod` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$name = mysql_query("SELECT `name` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$named = mysql_query("SELECT `name` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$list = mysql_query("SELECT `list` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$priced = mysql_query("SELECT `price` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$cost = mysql_query("SELECT `price` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$specs = mysql_query("SELECT `specs` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$pdf = mysql_query("SELECT `pdf` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$active = mysql_query("SELECT `active` FROM products WHERE `active`='Yes' LIMIT $start, $per_page") or die(mysql_error());
$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);
$num_rows = ceil(mysql_num_rows($result)/$num_columns);
// Echo the results
?>
<table width="500" border="1" bordercolor="black" cellpadding="0" cellspacing="0" style="border-left-width:0px; border-top-width: 1px; border-bottom-width: 0px; border-right-width: 0px;">
<tr width="500">
<td width="40">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Export</font></b>
</td>
<td width="25">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Delete</font></b>
</td>
<td width="25">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Edit</font></b>
</td>
<td width="250">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Manufacturer</font></b>
</td>
<td width="160">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Model</font></b>
</td>
<td width="50">
<b><font face="Tahoma,Verdana,Arial" size="0.90em">Price</font></b>
</td>
</tr>
<?
for ($r = 0; $r < $max_num_rows; $r++){
echo "<tr width=\"500\" height=\"5\">\n";
for ($c = 0; $c < $max_num_columns; $c++){ // 1
	$x = $r * $max_num_columns + $c;
	if ($x < mysql_num_rows($result)){
//                   $y = mysql_result($result, $x, 0); // Commented out so I could show your example
                     $num = mysql_result($result, $x, 0);
				$name = mysql_result($named, $x, 0);
				$make = mysql_result($maker, $x, 0);
				$price = mysql_result($priced, $x, 0);
				$cost = mysql_result($cost, $x, 0);
                     $cat = mysql_result($cat, $x, 0);
                     $subcat = mysql_result($subcat, $x, 0);
                     $man = mysql_result($man, $x, 0);
                     $mod = mysql_result($mod, $x, 0);
                     $list = mysql_result($list, $x, 0);
                     $specs = mysql_result($specs, $x, 0);
                     $pdf = mysql_result($pdf, $x, 0);
                     $active = mysql_result($active, $x, 0);
$unformated_price = $price;
$price = number_format($unformated_price, 2, '.', ',');
                   $y = <<<HTML
<td width="40" align="center" valign="middle">
<a href="ebay_generator.php?mod={$num}" target="_blank"><img src="images/ebaybutton.gif" border="0"></a>
</td>
<form action="admin.php">
<td width="25" valign="middle">
<center>
<font face="Tahoma,Verdana,Arial" size="0.80em">
<input type="hidden" name="action" value="Remove">
<input type="hidden" name="cat" value="{$cat}">
<input type="hidden" name="subcat" value="{$subcat}">
<input type="hidden" name="man" value="{$make}">
<input type="hidden" name="mod" value="{$mod}">
<input type="hidden" name="oldmod" value="{$mod}">
<input type="hidden" name="name" value="{$name}">
<input type="hidden" name="list" value="{$list}">
<input type="hidden" name="price" value="{$price}">
<input type="hidden" name="specs" value="{$specs}">
<input type="hidden" name="pdf" value="{$pdf}">
<input type="hidden" name="active" value="No">
<input type="image" src="images/drop.gif" border="0"></font>
</center>
</td>
</form>
<form action="admin.php" method="post">
<td width="25" valign="middle">
<center>
<font face="Tahoma,Verdana,Arial" size="0.80em">
<input type="hidden" name="action" value="Edit">
<input type="hidden" name="cat" value="{$cat}">
<input type="hidden" name="subcat" value="{$subcat}">
<input type="hidden" name="man" value="{$make}">
<input type="hidden" name="mod" value="{$mod}">
<input type="hidden" name="name" value="{$name}">
<input type="hidden" name="list" value="{$list}">
<input type="hidden" name="price" value="{$price}">
<input type="hidden" name="specs" value="{$specs}">
<input type="hidden" name="pdf" value="{$pdf}">
<input type="hidden" name="active" value="{$active}">
<input type="image" src="images/edit.gif" border="0"></font>
</center>
</td>
</form>
<td width="250">
<font face="Tahoma,Verdana,Arial" size="0.80em">{$make}</font>
</td>
<td width="160">
<font face="Tahoma,Verdana,Arial" size="0.80em">{$num}</font>
</td>
<td width="50">
<font face="Tahoma,Verdana,Arial" size="0.80em">{$price}</font>
</td>
HTML;

                }
                else {
                   $y = '';
                }
	echo "$y";
}
echo "</tr>\n";
}

// Echo page numbers
echo "</table></center><center>\n";
echo "<table width=480 cellspacing=0 cellpadding=0 border=0><tr><td><font face=\"Tahoma,Verdana,Arial\" size=0.50em><center>Go to: ";
// Echo the results
for ($i=1;$i <= $total_pages;$i++) {
if ($i == $page) echo " $i "; else echo " <a href=\"?action=List&page=$i\">$i</a> ";}
?>
</font></center></td></tr></table>
</div>
</font>
</div>
<br>
<?
}
?>

Link to comment
Share on other sites

Does NO one have an idea on this? I don't understand why no one has been able to answer the last few posts I made. Either someone posts something totally irrelevant or they just don't post at all. I am obviously not frustrated at anyone on here, just this problem, but it doesn't help when I am genuinely stuck and can't get any help. The last few posts I have looked for help on here for I actually had to solve myself, so its beginning to be a habit. It seems like there are quite a bit of people on here with programs like PhpDesigner and the like who just run through these posts, copy and paste the persons code, and then just type in whatever error the program displays.

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.