Page 1 of 1

code ideas for a php / mysql script.

Posted: Thu Jun 06, 2002 12:49 am
by SlowSpeed
newbie here. I have wrote scripts in .t and .tea for over 3 years @work.
I'm switching over to php/mysql for my land cruiser site. I would like ideas
and code examples on how to do a certain operation.

I have a vehicle registry where a user enters their info along with
the info of their cruizer. I know how to enter and retrieve the data with no problem at all.

for example:

lets say I have 30 entries into the database. when a user clicks on my reg
index page I would like to grab the first 5 entries (1-5) and display them, with a next 5 link at the bottom linking to the next 5 entries in the db. On that page it would show a previous and next link also.

how would everyone here go about doing the count in the for() to only showing 5 at a time.


thanks,
rodney

Posted: Thu Jun 06, 2002 2:55 am
by MattF
How about this:

Code: Select all

<?
if(!isset($_GET&#1111;'start'])) &#123;
    $_GET&#1111;'start'] = 0;
&#125;
$result = mysql_query("SELECT * FROM table limit ".$_GET&#1111;'start'].",5");
while($row = mysql_fetch_array($result))
&#123;
echo "$row<br>";
&#125;
$total = mysql_query("SELECT * FROM table");
if($_GET&#1111;'start'] >= 5) echo "<a href="". $_SERVER&#1111;'PHP_SELF']."?start=".$_GET&#1111;'start']-5."">Prev</a>";
if($_GET&#1111;'start'] < mysql_num_rows($total)) echo " <a href="". $_SERVER&#1111;'PHP_SELF']."?start=".$_GET&#1111;'start']+5."">Next</a>";
?>
That should work but I haven't tested it.

thanks

Posted: Thu Jun 06, 2002 3:26 pm
by SlowSpeed
thanks that is close to what I have..I will give this a try and let you know..

thanks again :)