Get Paid to Participate     Twitter     Facebook     Google+
Hosting Discussion
 

forgot password?


Reply


Old
  Post #1 (permalink)   06-14-2004, 11:32 AM
HD Guru
 
Join Date: Oct 2003
Location: Michigan, USA
Posts: 553

Status: Vovex Technology is offline
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%">&nbsp;</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%">&nbsp;</td>
<td width="26%"><br>
&nbsp;
<? 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>
__________________
Jonathan
 
 
 


Old
  Post #2 (permalink)   06-14-2004, 01:24 PM
HD Guru
 
Join Date: Oct 2003
Location: Michigan, USA
Posts: 553

Status: Vovex Technology is offline
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%">&nbsp;</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>&nbsp;</td>";
echo "<td><BR>&nbsp;$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>
__________________
Jonathan
 
 
 


Old
  Post #3 (permalink)   06-14-2004, 08:56 PM
HD Master
 
Join Date: Mar 2004
Location: Stanwood, WA
Posts: 294
Send a message via ICQ to FatalSw1tch Send a message via AIM to FatalSw1tch Send a message via Yahoo to FatalSw1tch

Status: FatalSw1tch is offline
you could have put the mysql close just at the bottom before the ?>
 
 
 
Reply

Thread Tools

New Post New Post   Old Post Old Post
Posting Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Sponsored By: