Page 1 of 1

Retrieve multiple rows

Posted: Fri Sep 10, 2004 8:34 am
by Kingo
Hello,
I'm trying to retrieve multiple rows{ My table has 24 rows}. But my code below displays only the first row. Your help is really appreciated.
Here is my code.

Code: Select all

$result1 = MYSQL_QUERY("SELECT * from data1 WHERE UserName='$username'")
   or die ("Name and password not found or not matched");

$worked1 = mysql_fetch_array($result1);

if($worked1)
{
$Y_Name1 =  $worked1["Year"]; 
$T_Name1 =  $worked1["Type"]; 
$S_Name1 =  $worked1["Subject"];
$V_Name1 =  $worked1["Value"];

echo "Year : $Y_Name1 <br>";
echo "Type : $T_Name1<br>";
echo "Subject : $S_Name1<br>";
echo "Value : $V_Name1<br>";

}

Re: Retrieve multiple rows

Posted: Fri Sep 10, 2004 8:44 am
by qads

Code: Select all

$result1 = MYSQL_QUERY("SELECT * from data1 WHERE UserName='$username'")or die ("Name and password not found or not matched");
while($worked1 = mysql_fetch_array($result1))
{
$Y_Name1 =  $worked1["Year"]; 
$T_Name1 =  $worked1["Type"]; 
$S_Name1 =  $worked1["Subject"];
$V_Name1 =  $worked1["Value"];
echo "Year : $Y_Name1 <br>";
echo "Type : $T_Name1<br>";
echo "Subject : $S_Name1<br>";
echo "Value : $V_Name1<br>";
}

Posted: Fri Sep 10, 2004 9:26 am
by Kingo
Thanx very much. I have another question. I want to display the values in a form. I mean i want to bind the form to the database and siaply the values in the form. Your help is appreciated. [ I was able to do for single row--but here there are multiple rows and i dont know how to handle them]

Posted: Fri Sep 10, 2004 9:47 am
by PrObLeM
i think this is what you want...

Code: Select all

<textarea name="NAME" cols="80" rows="6">$WHATEVERVALUE YOU WANT IN HERE(MULTI LINE)</textarea>

//or

<input type="text" name="NAME" value="$WHATEVERVALUE YOU WANT IN HERE(SINGLE LINE)">

Posted: Fri Sep 10, 2004 9:57 am
by Kingo
Nope.

Code: Select all

$result1 = MYSQL_QUERY("SELECT * from data1 WHERE UserName='$username' order by 'Year' ")   or die ("Name and password not found or not matched");
echo "<table border="1" >";

while($worked1 = mysql_fetch_array($result1))
{
$Y_Name1 =  $worked1["Year"]; 
$T_Name1 =  $worked1["Type"]; 
$S_Name1 =  $worked1["Subject"];
$V_Name1 =  $worked1["Value"];

echo "<tr><td>$Y_Name1 </td>";
echo "<td>$T_Name1</td>";
echo "<td>$S_Name1</td>";
echo "<td>$V_Name1</td></tr>";

}
echo "</table>";
With the above code I'm displaying the contents of the table from the datadase onto a HTML table. I want to display the contents of the table from the database onto a HTML FORM. I mean how do i assign values to the text boxes in the form. I'm confused because I'm having multiple rows.

If it were single row i would do thsi way and it works..Please suggest me what to do for multiple rows.

Code: Select all

$result = MYSQL_QUERY("SELECT * from data WHERE UserName='$username'and PassWord='$password'")
   or die ("Name and password not found or not matched");

$worked = mysql_fetch_array($result);

if($worked)
{
$S_Name =  $worked["School_Name"]; 
$P_Name =  $worked["Principal_Name"]; 

echo "<form name="form9" method="post" action="review.php"> ";
echo "<div align="center"> <table width="640" border="0" align="center" cellpadding="2" cellspacing="0"> ";
echo "<tr><td colspan="7" align="center"> ";

echo "School Name: <input name="schoolname" type="text"  value= "$S_Name"  size="35"> ";
echo "</tr> <tr> <td width="118" valign="top">Principal:</td> ";

echo "<td width="122"><input name="principal" type="text"  value= "$P_Name"  size="15"></td>";

echo "<div align="center"><br><input type="submit" name="Submit" value="Submit"> ";


echo "</div></form>";

so close

Posted: Fri Sep 10, 2004 11:04 am
by phpScott
you are so close by the looks of it.

take your while loop and put it after your if statement, essential combine the two using your while loop to keep assembling each row of your form.

phpscott

Posted: Fri Sep 10, 2004 2:59 pm
by Kingo
I am not able to get the functionality. If any one could give me a idea, i would really appreciate it
Thanx