PHP循环为循环中的每个项目提供相同的结果
我在自定义CMS中有一个循环,它创建了一个下拉列表,允许我选择和更改帖子的作者 不幸的是,它不起作用,每个选项都有语法“selected”,而它应该只是其中之一 我做了什么PHP循环为循环中的每个项目提供相同的结果,php,loops,Php,Loops,我在自定义CMS中有一个循环,它创建了一个下拉列表,允许我选择和更改帖子的作者 不幸的是,它不起作用,每个选项都有语法“selected”,而它应该只是其中之一 我做了什么 while ($row = mysql_fetch_array($rows)) { printf ('<option value=%d',$auth_id); if ($auth_id == $current_auth) { echo ' selected'; } printf (">%s", $
while ($row = mysql_fetch_array($rows)) {
printf ('<option value=%d',$auth_id);
if ($auth_id == $current_auth) {
echo ' selected';
}
printf (">%s", $name);
}
while($row=mysql\u fetch\u数组($rows)){
printf('$auth\u id
在任何地方都不会更改。您的脚本可能如下所示
$auth_id = 0;
$current_auth = 1;
while ($row = mysql_fetch_array($rows)) {
$auth_id++; // ?? change here
printf ('<option value=%d',$auth_id);
if ($auth_id == $current_auth) {
echo ' selected';
}
printf (">%s", $row['name']);
}
$auth\u id=0;
$current_auth=1;
while($row=mysql\u fetch\u数组($rows)){
$auth_id++;//?在此处更改
printf('$auth\u id
在任何地方都不会更改。您的脚本可能如下所示
$auth_id = 0;
$current_auth = 1;
while ($row = mysql_fetch_array($rows)) {
$auth_id++; // ?? change here
printf ('<option value=%d',$auth_id);
if ($auth_id == $current_auth) {
echo ' selected';
}
printf (">%s", $row['name']);
}
$auth\u id=0;
$current_auth=1;
while($row=mysql\u fetch\u数组($rows)){
$auth_id++;//?在此处更改
printf(“您需要将$auth\u id和$name替换为行中的数据,例如$row['auth\u id']或您字段的名称。您需要将$auth\u id和$name替换为行中的数据,例如$row['auth\u id']或者不管您的字段名是什么。看起来您在代码中根本没有使用$row,对吗?当然$auth\u id和$current\u auth不会更改。看起来您在代码中根本没有使用$row,对吗?当然$auth\u id和$current\u auth不会更改。您在哪里设置值$auth\u id
和$current\u auth
?在哪里设置值$auth\u id
和$current\u auth
?