code ideas for a php / mysql script.

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
SlowSpeed
Forum Newbie
Posts: 2
Joined: Thu Jun 06, 2002 12:49 am
Location: wa
Contact:

code ideas for a php / mysql script.

Post 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
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post 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.
SlowSpeed
Forum Newbie
Posts: 2
Joined: Thu Jun 06, 2002 12:49 am
Location: wa
Contact:

thanks

Post by SlowSpeed »

thanks that is close to what I have..I will give this a try and let you know..

thanks again :)
Post Reply