mysql_fetch_row problem code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
sulen
Forum Commoner
Posts: 79
Joined: Wed Jul 09, 2003 4:55 pm
Location: los angeles
Contact:

mysql_fetch_row problem code

Post by sulen »

This is the code that I am using to perform the required functions spoken about.

mysql_select_db("altura");

$sql = "select * from directory where pno like '%".$pno."%'";

$result = mysql_query($sql);
//$num_results = mysql_num_rows($result);

//for($i=0; $i <$num_results; $i++)

while($i = mysql_fetch_row($result))
{
echo $i[3];?>
<form action='uconfirm.php' method='post'>
<p>Update Employee Information</p>
<p> Last Name
<input type=text size=40 name=lname value=<?=$i[0]?>>
<br><BR>
First Name
<input type=text size=40 name=fname value=<?=$i[1]?>>
<br><BR>
Branch
<input type=text size=40 name=region value=<?=$i[2]?>>
<br><BR>
Title
<input type=text size=40 value=<?=$i[3]?>>
<br><BR>
<input type=submit value=Update></p></form></body>
</html>
<?
}
?>
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Try this one out

Post by thomas777neo »

Code: Select all

<?
mysql_select_db("altura"); 

$sql = "select * from directory where pno like '%".$pno."%'";//could return more than one result, but we will presume it will only return 1 value(Try and be more specific in the select, rather use the employees id)

$result = mysql_query($sql); 

$i=0;
$employee&#1111;0]&#1111;"numrows"]=mysql_num_rows($result);
	
while ($employee&#1111;0]&#1111;"numrows"]>$i)&#123;

$employee&#1111;$i]&#1111;"lname"]=mysql_result($result,$i,"lname");//lname = database column name
$employee&#1111;$i]&#1111;"fname"]=mysql_result($result,$i,"fname");
$employee&#1111;$i]&#1111;"region"]=mysql_result($result,$i,"region");
$employee&#1111;$i]&#1111;"title"]=mysql_result($result,$i,"title");
?>
<p> Last Name 
<input type="text" size=40 name="lname" value="<? echo $employee&#1111;$i]&#1111;"lname"]; ?>">
<br><BR> 
First Name 
<input type="text" size=40 name="fname" value="<? echo $employee&#1111;$i]&#1111;"fname"]; ?>">
<br><BR> 
Branch 
<input type="text" size=40 name="region" value="<? echo $employee&#1111;$i]&#1111;"region"]; ?>">
<br><BR> 
Title 
<input type="text" size=40 name="title" value="<? echo $employee&#1111;$i]&#1111;"title"]; ?>"> 
<br><BR> 
<input type=submit value=Update></p>
<?
$i++;
&#125;
?>
</form></body> 
</html>
Note: I haven't ran this and checked it. Due to the fact that I don't have you database. But the concept is there. Enjoy...
Post Reply