欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

大神请进:php代码循环问题.

程序员文章站 2024-02-17 20:56:34
...
之前代码验证mysql连接无误.
这里我想实现的是:activite返回1个以上的参数的话,对每个参数进行sql查询,然后把每个查询结果显示出来,可是我的是个死循环,可且就是返回一个参数,也不显示结果,请问是这么回事呢?
mysql_select_db($mysql_database,$link);
if (isset($_POST["activite"])) {
for($i=0;$i $strsql="select n_naps from activage where famille='$activite[$i]'";
echo $strsql;
$result=mysql_query($strsql);
$nb=mysql_num_rows($result);
for($i=1;$i $info=mysql_fetch_row($result);
echo "$info[0]
";
}
}
}
谢谢各位大神的指教.


回复讨论(解决方案)

出错了!
1、for($i=0;$i 没有看到对 $activite 赋值
2、$strsql="select n_naps from activage where famille='$activite[$i]'"
应写作
$strsql="select n_naps from activage where famille=' {$activite[$i] }'"

出错了!
1、for($i=0;$i 没有看到对 $activite 赋值
2、$strsql="select n_naps from activage where famille='$activite[$i]'"
应写作
$strsql="select n_naps from activage where f……
版主大人,谢谢你每次都有回答我的一些白痴问题啊,我把问题说的在细点吧:
在1.php中有代码如下:
Activités gymniques

Activités gymniques aquatiques

Activités fitness/forme

Activités douces/ bien-être

2.php接收1.php中的参数:局部代码如下:
之前验证连接数据库无误。
$activite=isset($_POST["activite"])?$_POST["activite"]:"";
if (isset($_POST["activite"])) {
for($i=0;$i $strsql="select n_naps from activage where famille='{$activite[$i]}'" ;
echo $strsql;
$result=mysql_query($strsql);
$nb=mysql_num_rows($result);
echo $nb;
for($i=1;$i $info=mysql_fetch_row($result);
echo "$info[0]
";
}
}
}
按照版主大人说的改了下,其中在1.php中单选了Activités gymniques 选项,上面代码结果输出为:
select n_naps from activage where famille='activités gymniques'0
不知道为什么查询结果是0,我复制粘贴的这段话放到mysql中,找到了4个结果.

这里是0,不知道为啥...

引用 1 楼 xuzuning 的回复:出错了!
1、for($i=0;$i 没有看到对 $activite 赋值
2、$strsql="select n_naps from activage where famille='$activite[$i]'"
应写作
$strsql="select n_naps f……
对2楼的补充啊,如果把where之后的都去掉,就显示出所有的n_naps了,就是说问题出在where哪里了,但是我实在找不出哪里有错啊....就是写$strsql="select n_naps from activage where famille='activités gymniques'还是说是0的......

字符 é 在中文操作系统中是2字节的,其内码与所用字符集有关