Forum Moderators: coopster

Message Too Old, No Replies

While loop within another loop

         

omoutop

12:49 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi to everybody!
Just a simple question...I have created this loop within another loop...

/////////////////////////
<? $Querytype = "select distinct type from Type";
$resulttype = mysql_query($Querytype);
$timestype = mysql_num_rows($resulttype);
$i = 1;
while ($rowtype = mysql_fetch_assoc($resulttype))
{
$type = $rowtype ['type'];
while ($i <= $timestype)
{
echo $type;
?>
<input type="checkbox" name="type<? echo $i?>" value="<? echo $type?>">
<?

$i++;
};
};
///////////////////
which returns:
Hotel<input type="checkbox" name="type1" value="Hotel">
Hotel<input type="checkbox" name="type2" value="Hotel">
Hotel<input type="checkbox" name="type3" value="Hotel">
Hotel<input type="checkbox" name="type4" value="Hotel">

instead of:
Hotel<input type="checkbox" name="type1" value="Hotel">
Hotel<input type="checkbox" name="type2" value="Apartment">
Hotel<input type="checkbox" name="type3" value="Studio">
Hotel<input type="checkbox" name="type4" value="Bankalow">

ANY IDEAS?

omoutop

12:59 pm on Jul 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



DONE....

This is what I needed :S

<? $Querytype = "select * from Type";
$resulttype = mysql_query($Querytype);
$timestype = mysql_num_rows($resulttype);
$i = 1;
while ($rowtype = mysql_fetch_assoc($resulttype) AND $i <= $timestype)
{
$type = $rowtype ['type'];

echo $type;
?>
<input type="checkbox" name="type<? echo $i?>" value="<? echo $type?>">
<?

$i++;

};

?>