Web Hosting Talk







View Full Version : Php Coding help


sngskunk
12-06-2005, 05:25 PM
Okay i have the code below so that it will show the information in the mysql database. The thing is, is this shows everything. I would like it to only show the latest 5. So what can i do to my script so that will happen. Thanks!

<?
include "class_db.php";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM site_roster";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$fname=mysql_result($result,$i,"fname");
$lname=mysql_result($result,$i,"lname");
$alias=mysql_result($result,$i,"alias");

?>

<b><a href="r_update.php?id=<? echo $id; ?>"><? echo $fname; ?> "<? echo $alias; ?>" <? echo $lname; ?></a></b><br>

<?php

$i++;
}

?>

Thanks Ahead!!!

Carp
12-06-2005, 05:28 PM
$query="SELECT * FROM site_roster LIMIT 5";

sngskunk
12-06-2005, 06:57 PM
Okay thanks that helped, but know i have another question.

I want names to be put into a table like this below out of a mysql database using php, how can i do this.

___________________________________________________
| Name1 | Name2 | Name3 | Name4 | Name5 | Picture |
|--------------------------------------------------------- | Here |
| Name6 | Name7 | Name8 | Name9 | Name10 | In Last Column |
|____________________________________|_____________|

Not the best table at all but hopefuly you get the idea how can i do this??? Thanks

Oras
12-06-2005, 07:34 PM
The table contains 10 names not 5 as you mentioned, anyway you can do this:


while($r=mysql_fetch_array($result))
{
name[]=$r['field_name'];
}

now you have name[0], name[1], name[2] ... etc. put them inside HMTL code.
regards