gpt4 book ai didi

php - 回显 mysql_num_rows 的所有行

转载 作者:搜寻专家 更新时间:2023-10-31 21:06:41 26 4
gpt4 key购买 nike

我有以下 php

  $q=mysql_query("select SMILES from GeoAndEnergies where Weight='".$data."' ") or die(mysql_error());
$n=mysql_num_rows($q); //not mysql_fetch_row, as that does not return count but an array
if($n>0)
{
$info=mysql_fetch_row($q);
echo $info[0];
}
else {
echo "molecule not find";
}

我不仅要回显 $info[0],还要回显 $info[0]+"<"+ $info[1] + "<".... + $info[n],那会是什么语法正确吗?

谢谢

最佳答案

使用while 循环获取所有行

$q=mysql_query("select SMILES from GeoAndEnergies where Weight='".$data."' ") or die(mysql_error());
$n=mysql_num_rows($q);

if($n>0)
{
$val='';
while($info=mysql_fetch_row($q))
{
if($val!='')
$val.=' < ';
$val.= $info[0];
}
}
else {
$val= "molecule not find";
}
echo $val;

关于php - 回显 mysql_num_rows 的所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31179362/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com