Hello everyone,
I am a self-taught PHP newbie (via trial and error) and have a small ministry, which builds sites for other ministries.
I was hoping someone could help me tweak this script?
I finally got it to show the pages in 10 rows with links to and fro, but after the last full page of vehicles it keeps going to 'Next >>'. Apparently it doesn't know how many records there are.
I figured out using mysql_num_rows() will count the row #s, but how do I apply that to the links to 'put the brakes on' for the 'Next >>' link on the last page of records?
Another problem is that they are contantly adding and deleting vehicle inventory so the row #s would always be changing. Then I couldn't put a set value in ceil().
Is there anyway to set a wildcard with ceil() or something similar like this?
PHP Code:
*/ In the Main Section */
$result = mysql_query("SELECT * FROM inventory"); $num_rows = mysql_num_rows($result); $num_rows = $lastpage; */ Then add this to the Next Link Section */
if ($lastpage=stop) { echo " "; }
** The $$price in the script below is actually: & # 3 6 ; $price w/o spaces.
PHP Code:
<? if (isset($_GET['start'])) { $start = $_GET['start']; } else { $start = 0; } $dbuser = "user"; $dbserver = "localhost"; $dbpass = "pass"; $dbname = "name"; mysql_connect($dbserver, $dbuser, $dbpass) or die ("UNABLE TO CONNECT TO DATABASE"); mysql_select_db($dbname) or die ("UNABLE TO SELECT DATABASE"); $sql = "SELECT * FROM inventory ORDER BY ref ASC LIMIT $start , 10"; $result = mysql_query($sql) or die(mysql_error()); if ($myrowsel = mysql_fetch_array($result)) { do { $id=$myrowsel['id']; $ref=$myrowsel['ref']; $year=$myrowsel['year']; $make=$myrowsel['make']; $model=$myrowsel['model']; $price=$myrowsel['price']; switch ($shade) { case 'row_lite': $shade = 'row_drk'; break; case 'row_drk': $shade = 'row_lite'; break; default: $shade = 'row_lite'; break; } echo " <tr> <td valign=top class=$shade> <table width=100% cellspacing=0 cellpadding=3> <tr> <td width=75 align=center valign=middle><img src=list/$ref.jpg alt='Image not available' width=75 height=56></td> <td width=100 nowrap class=reg>Ref# $ref</td> <td width=250 nowrap class=reg>$year $make $model</td> <td width=70 nowrap class=reg>$$price</td> <td width=100%> </td> </tr> </table> </td> </tr> "; } while ($myrowsel = mysql_fetch_array($result)); } ?> </table> </td> </tr> </table> </td> </tr> <tr> <td width=100% valign=top colspan=2> <table width=100% cellspacing=0 cellpadding=3> <tr> <td width=10> </td> <td width=50%> <? if (isset($_GET['start'])) { $start = $_GET['start']; } else { $start = 0; } for($i = $start; $i > $start - 10; $i--) { if ($i == $start - 9) { echo "<a class=lnk href=list.php?start=".($i-1).">« Previous page</a>"; } } ?> </td> <td width=50% align=right> <? if (isset($_GET['start'])) { $start = $_GET['start']; } else { $start = 0; } for($i = $start; $i < $start + 10; $i++) { if ($i == $start + 9) { echo "<a class=lnk href=list.php?start=".($i+1).">Next page »</a>"; } } ?>
Thanks,
xsfssg
Last edited by xsfssg; 12-11-2005 at 10:45 AM..
|