我想这应该是一件容易的事情。我是个新手,你会在我草率的代码中看到这一点,但是我不能让这个for循环在更大的while循环中工作。我得到了一个解析错误,但我已经检查了数百次代码,没有找到缺少的分号或逗号。任何建议都是值得感谢的。
谢谢!
$result = mysql_query("SELECT `alias`, `max_seats` FROM `rsvp` WHERE `id` = '$id' ");
$alias = $r['alias'];
$seats = $r['max_seats'];
while($r = mysql_fetch_array($result)){
echo '<h3>Welcome, ' . $alias . '. Please complete your RSVP</h3>';
echo '<form class="register" method="post">';
echo '<input type="radio" id="responded" name="responded" value="1">Attending (confirm details in the next step)<br />';
echo '<input type="radio" id="responded" name="responded" value="0"><em><strong>NOT</strong></em> Attending (we\'re sorry you can\'t make it!)<br /><div class="hide" id="hide1">';
echo '<p>Please select the number of seats you\'d like to confirm (' . $seats . ' seats maximum)</p>';
echo '<label for="seats">Seats</label>';
echo '<select name="seats" id="seats">';
for ($i=1; i=$seats; $i++){
echo '<option value="' . $i . '">' . $i . '</option>';
}
echo '</select> <input type="text" placeholder="How many Chicken?"></input><br />';
echo '<input type="text" placeholder="How many Beef?"></input><br /></div>';
echo '<input type="reset" value="Clear"><input type="submit" value="Submit"></form>';发布于 2013-01-25 15:22:43
可以,您可以使用嵌套循环!Click Me!
修复for循环
for ($i=1; $i <= $seats; $i++){
echo '<option value="' . $i . '">' . $i . '</option>';
}条件$i = $seats不是比较(它是赋值),只有当$seats为零时才返回false,对于每个条件,它将返回true,并且在每次迭代之后,$i的值将被设置为$seats的值
比较的正确方式可以是
$i != $seats // not equals
$i == $seats // equals
$i > $seats // greater than
$i < $seats // less than
$i >= $seats // greater then or equal
$i <= $seats // less then or equal $result = mysql_query("SELECT `alias`, `max_seats` FROM `rsvp` WHERE `id` = '$id' ");
$alias = $r['alias'];
$seats = $r['max_seats'];
while($r = mysql_fetch_array($result))
{
echo '<h3>Welcome, ' . $alias . '. Please complete your RSVP</h3>';
echo '<form class="register" method="post">';
echo '<input type="radio" id="responded" name="responded" value="1">Attending (confirm details in the next step)<br />';
echo '<input type="radio" id="responded" name="responded" value="0"><em><strong>NOT</strong></em> Attending (we\'re sorry you can\'t make it!)<br /><div class="hide" id="hide1">';
echo '<p>Please select the number of seats you\'d like to confirm (' . $seats . ' seats maximum)</p>';
echo '<label for="seats">Seats</label>';
echo '<select name="seats" id="seats">';
for ($i=1; $i <= $seats; $i++){
echo '<option value="' . $i . '">' . $i . '</option>';
}
echo '</select> <input type="text" placeholder="How many Chicken?"></input><br />';
echo '<input type="text" placeholder="How many Beef?"></input><br /></div>';
echo '<input type="reset" value="Clear"><input type="submit" value="Submit"></form>';
}发布于 2013-01-25 15:23:46
是的..您可以在while循环中使用for循环。在您的代码中,您缺少一个$ in for循环。应该只是这样。您还需要在for循环中编写一个条件。
for ($i=1; $i==$seats; $i++){发布于 2013-01-25 15:25:08
这是正确的,请检查一次.
$result = mysql_query("SELECT `alias`, `max_seats` FROM `rsvp` WHERE `id` = '$id' ");
while($r = mysql_fetch_array($result)){
$alias = $r['alias'];
$seats = $r['max_seats'];
echo '<h3>Welcome, ' . $alias . '. Please complete your RSVP</h3>';
echo '<form class="register" method="post">';
echo '<input type="radio" id="responded" name="responded" value="1">Attending (confirm details in the next step)<br />';
echo '<input type="radio" id="responded" name="responded" value="0"><em><strong>NOT</strong></em> Attending (we\'re sorry you can\'t make it!)<br /><div class="hide" id="hide1">';
echo '<p>Please select the number of seats you\'d like to confirm (' . $seats . ' seats maximum)</p>';
echo '<label for="seats">Seats</label>';
echo '<select name="seats" id="seats">';
for ($i=1; $i=$seats; $i++){
echo '<option value="' . $i . '">' . $i . '</option>';
}
echo '</select> <input type="text" placeholder="How many Chicken?"></input><br />';https://stackoverflow.com/questions/14517176
复制相似问题