MySQL Loop problem

I am trying to configure a basic PHP program. So far my script can add people to a clientel base. But when I try to view a list of who is in the database. It only shows the first result. It wont loop through and grab the rest.

Someone help please.

Here is the code
--------------------------------------------

<html>
<head>
<title>Client View List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
Sort by: <br>
<br>

<?
$username="********";
$password="********";
$database="********";

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

$num=mysql_numrows($result);

mysql_close();

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

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$address=mysql_result($result,$i,"address");
$suite=mysql_result($result,$i,"suite");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$zip=mysql_result($result,$i,"zip");
$phone=mysql_result($result,$i,"phone");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");

++$i;
}

?>
<table width="90%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="5%"> </td>
<td width="26%" bgcolor="#CCCCCC"><b>Name</b></td>
<td width="22%" bgcolor="#CCCCCC"><b>Phone</b></td>
<td width="17%" bgcolor="#CCCCCC"><b>City / State</b></td>
<td width="30%" bgcolor="#CCCCCC"><b>Email Address</b></td>
</tr>
<tr>
<td width="5%"> </td>
<td width="26%"><br>
 
<? echo "$first $last<BR>" ?>
</td>
<td width="22%"> <br>
<? echo "$phone<BR>" ?>
</td>
<td width="17%"> <br>
<? echo "$city , $state<BR>" ?>
</td>
<td width="30%"> <br>
<? echo "$email<BR>" ?>
</td>
</tr>
</table>
</body>
</html>
 
Never mind. I figured it out. Im a moron :)

Just in case you guys wanted the code. Here ya go.


Working Code
----------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
Sort by: <br>
<br>
<table width="90%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="5%"> </td>
<td width="26%" bgcolor="#CCCCCC"><b>Name</b></td>
<td width="22%" bgcolor="#CCCCCC"><b>Phone</b></td>
<td width="17%" bgcolor="#CCCCCC"><b>City / State</b></td>
<td width="30%" bgcolor="#CCCCCC"><b>Email Address</b></td>
</tr>

<?
$username="***********";
$password="***********";
$database="***********";

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

$num=mysql_numrows($result);

mysql_close();

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

$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$address=mysql_result($result,$i,"address");
$suite=mysql_result($result,$i,"suite");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
$zip=mysql_result($result,$i,"zip");
$phone=mysql_result($result,$i,"phone");
$fax=mysql_result($result,$i,"fax");
$email=mysql_result($result,$i,"email");

echo "<tr>";
echo "<td> </td>";
echo "<td><BR> $first $last<br></td>";
echo "<td><BR>$phone<BR></td>";
echo "<td><BR>$city , $state<BR></td>";
echo "<td><BR>$email<BR></td>";
echo "</tr>";

++$i;
}

?>
</table>
</body>
</html>
 

Forum statistics

Threads
80,998
Messages
248,557
Members
20,684
Latest member
mikstrahost
Top