Click to See Complete Forum and Search --> : SQL and loops


MacMyDay
08-07-2003, 10:17 AM
I have this form which consists of the following:


<TR><TD><input type=text name='name' style='width:80px;'></TD>
<TD><input type=text name='blah' style='width:90px;'></TD>
<TD><input type=text name='blahblah' style='width:200px;'></TD>
<TD><select NAME='rating'>
<option VALUE=''> -- Rating --
<OPTION VALUE='Blah'>Blah
<OPTION VALUE='Blah'>Blah
</select><br>



What I want to do is to have it displayed as many times as there are results in the database for that user. All I know at the moment is it'd start with $query = mysql_query ("select * from list where username='$blah'");

Thanks in advance.

pyro
08-07-2003, 10:26 AM
Ok, what we do then is loop through the values that it returns, with something like this:

while($row = mysql_fetch_array($query)) {
echo $row[0]; #will echo the value of the first column in each row
}

MacMyDay
08-07-2003, 10:40 AM
Thanks for the start. Thing is that only selects the first column, for me. I need it to select everything and display it.

pyro
08-07-2003, 10:44 AM
Try this out:

while($row = mysql_fetch_array($query)) {
foreach ($row as $value) {
echo $value." "; #the ." " is to add a space after each item it prints
}
echo "<br>";
}

MacMyDay
08-07-2003, 10:47 AM
Getting there ;) It now just displays everything twice.

pyro
08-07-2003, 10:57 AM
Can I see your complete code?

MacMyDay
08-07-2003, 11:01 AM
Sure, but it's really only what you've given me.

<?
include ("header.php");
include ("connect.php");

$username = getusername();
$result = mysql_query ("select * from list where username='$username'");
while ( $row = mysql_fetch_array ($result)) {
foreach ( $row as $value ) {
echo $value." " ;
}
echo "<br>" ;
}
?>