Forum Moderators: coopster
$result=mysql_query("SELECT * FROM x WHERE parameter="y" ORDER BY z");
while($row=mysql_fetch_array($result))
echo "<input type=\"radio\" name=\"a\" value=\"".$row["b"]."\" checked=\"checked\" />";
What I'm trying to do is to get the first one that outputs to be checked, and the rest not to be checked. As written above, all will have the checked output which is invalid.
If this were a for statement, something like i=1;i<count;i++, then I could have a statement below that has a special condition if i==1.
Is there anything I can do like this for the while statement?
Might I be able to use the for statement and not mess up the output of the MySQL data?
Thanks
while($row = mysql_fetch_array($result)) {
if($row['field']!= "foobar") {
[url=http://us2.php.net/break]break[/url];
}
//continue with loop
}
Good luck! :)
[edited by: eelixduppy at 4:30 pm (utc) on Jan. 20, 2007]
$out = ''; // initialize
while (processing rows) {
$checked = ($out) ? '' : ' checked="checked"';
$out .= '<input type="radio" name="a" value="' . htmlentities($row['b']) . "$checked />";
}