一个我认为很难的问题。

rosen 2002-03-13 01:16:49
$aresult=mysql_query("select ID from table where name='abc'");
while ($myrow=mysql_fetch_row($aresult))
{
echo $myrow[0];
}
我的问题是:如果数据库中有一条以上的结果满足name='abc',那么这个时候的$myrow[0]返回的是很多个结果的集合,该怎么办?怎样区别开每一个结果?

...全文
55 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
rosen 2002-03-13
  • 打赏
  • 举报
回复
TO:anybody1(随便编一个)
我想做一个查询系统;比如说我现在要找性别为“男”的话,就有很多结果在一个区域内显示example:
$aresult=mysql_query("select name from table where sex='男'");
while ($myrow=mysql_fetch_row($aresult))
{
echo $myrow[0];
}
返回的是一串结果,
我现在就是要把他们在不同的表单域中显示。 netpirate(海盗) 兄的例子是对的,不过我还要改改,目前还没成功。
hbolive 2002-03-13
  • 打赏
  • 举报
回复
$aresult=mysql_query("select ID from table where name='abc'");
while ($myrow=mysql_fetch_array($aresult))
{
echo $myrow[0];
}
rosen 2002-03-13
  • 打赏
  • 举报
回复
试一下
goatherd7807 2002-03-13
  • 打赏
  • 举报
回复
用数组返回结果集,比如mysql_fetch_array()函数,然后输出
anybody1 2002-03-13
  • 打赏
  • 举报
回复
to:netpirate
for($i=0;$i<$nuum;$i++) 出错,应该是:
for($i=0;$i<$num;$i++)

to :rosen (考试机器)
你想怎样区别开每一个结果?详细点


pilchart2000 2002-03-13
  • 打赏
  • 举报
回复
TOP!!!
rosen 2002-03-13
  • 打赏
  • 举报
回复
不得不承认自己的差距,请各位以后多多指教。
海盗2019 2002-03-13
  • 打赏
  • 举报
回复
$aresult=mysql_query("select ID from table where name='abc'");
$num=mysql_num_rows($aresult);
for($i=0;$i<$nuum;$i++){
while ($myrow=mysql_fetch_row($aresult))
{
echo $myrow[$i]."<br>";
}
}
SimonDW 2002-03-13
  • 打赏
  • 举报
回复
怎么会是一个集合???
anybody1 2002-03-13
  • 打赏
  • 举报
回复
具体是用php和html结合实现的
当然,我这里边还用了一个分页
anybody1 2002-03-13
  • 打赏
  • 举报
回复
我有现成的,是一个婚介搜索引擎的,我以前做的
不过有很多你不需要的html代码,你自己看看吧!

<?
if(!empty($age1) && !empty($age2))
{
$mysql_db = mysql_connect("localhost", "root", "");
mysql_select_db("zhouhaostart",$mysql_db);
$sql="INSERT into hj_age(age1,age2)
VALUES('$age1','$age2')";
$sql_result=mysql_query($sql);
}
else
{print("<center>请您将年龄填清楚。<br>");
print("<a href=\"zhongjie.htm\">返回重填</a></center>");
}
$age3=$age1;
$age4=$age2;
$mysql_db = mysql_connect("localhost", "root", "");
mysql_select_db("zhouhaostart",$mysql_db);
$sql = "SELECT * from hj_inputanything where sex like '%$sex%' and birth_y>=$age3 and birth_y<=$age4 order by time DESC";
$sql_result = mysql_query($sql);
//计算总的记录条数
$sum=mysql_num_rows($sql_result);
if(empty($page))
{
$page=1;
}

$offset=$page*20-20;
$page_cnt=ceil($sum/20);

?>
。。
。。//html代码(你不需要的)
。。
。。
<td width="23%" height="33">
<div align="center"><b><font size="2">企点婚介信息搜索引擎</font></b></div>
</td>
<td width="30%" height="33">
<div align="center"></div>
</td>
<td width="27%" height="33"><font size="2"><font color="#FF0000"><a href="hj_tijiao.htm" target="_blank"><img src="../images/fabu_xxi.gif" width="28" height="30" border="0"></a><a href="hj_tijiao.htm" target="_blank">我要提交婚介信息</a></font></font></td>
</tr>
</table>
<table cellpadding="5" width="100%" style="font-size: 9pt" height="10" cellspacing="5" align="center">
<tr>
<td colspan="6" height="6">
<div align="left"><font color="#FF0000"><font size="2" color="#006600">共搜索到符合您查寻条件的婚介信息</font><font size="2">
<?print("$sum");?>
<font color="#006600">条        </font></font></font></div>
</td>
</tr>
<tr bgcolor="#FD283E">
<td height="19" width="81">
<div align="center"><font color="#FFFFFF">姓名 </font></div>
</td>
<td height="19" width="49">
<div align="center"><font color="#FFFFFF">年龄 </font></div>
</td>
<td height="19" width="89">
<div align="center"><font color="#FFFFFF">婚姻状况</font></div>
</td>
<td height="19" width="93">
<div align="center"><font color="#FFFFFF">居住地 </font></div>
</td>
<td height="19" width="87">
<div align="center"><font color="#FFFFFF">身高 </font></div>
</td>
<td height="19" width="76">
<div align="center"><font color="#FFFFFF">体重 </font></div>
</td>
<td height="19" width="113">
<div align="center"><font color="#FFFFFF">填表日期 </font></div>
</td>
</tr>
<?
$sql = "SELECT * from hj_inputanything where parentid=0 and sex like '%$sex%' and birth_y>=$age3 and birth_y<=$age4
order by time DESC LIMIT $offset, 20";
$sql_result = mysql_query($sql);
while ($sql_row = mysql_fetch_array($sql_result))
{
print("<tr>");
print("<td bgcolor=\"#dddddd\">
<a href=\"hj_xiangxi.php3?id=$sql_row[id]\">
$sql_row[name]</td>");
print("<td bgcolor=\"#dddddd\">$sql_row[birth_y]</td>");
print("<td bgcolor=\"#dddddd\">$sql_row[marriage]</a></td>");
print("<td bgcolor=\"#dddddd\">$sql_row[area]</td>");
print("<td bgcolor=\"#dddddd\">$sql_row[height1]</td>");
print("<td bgcolor=\"#dddddd\">$sql_row[weight]</td>");
print("<td bgcolor=\"#dddddd\">$sql_row[time]</td>");
print("</tr>");
}
mysql_close();

?>
</table>
<table width="100%" border="0" height="1" cellpadding="5" cellspacing="5" align="center">
<tr>

<td height="1">
<div align="right"></div>
</td>
</tr>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0" height="15">
<tr>
<td width="42%">
<div align="left"><font size="2" color="#333333"> </font><font size="2" color="#006600">第</font><font size="2" color="#FF0000">
</font> <font color="#FF0000" size="2">
<?
$start=$offset+1;
print("$start");
?>
<font color="#006600">条- 第</font></font> <font color="#FF0000" size="2">
<?
if($page!=$page_cnt)
{
$bottom=$offset+20;
}
else
{
$bottom=$sum;
}
print("$bottom");
?>
<font color="#006600">条   共</font></font> <font color="#FF0000" size="2">
<?print("$sum");?>
<font color="#006600">条</font></font></div>
</td>
<td width="27%"><font color="#333333" size="2"></font></td>
<td width="31%">
<div align="right"><font size="2" color="#006600">
<?
if($page!=1) //如果偏移量是0,则没有上一页的链接
{
$prepage=$page-1;
print("<a href=\"$PHP_SELF?page=$prepage\">上一页</a> \n");
}
if ($page_cnt!=0 && $page!=$page_cnt)
{
$backpage=$page+1;
print("<a href=\"$PHP_SELF?page=$backpage\">下一页</a> \n");
}

?>
共</font> <font color="#006600" size="2">
<?print("$page_cnt");?>
页</font></div>
</td>
</tr>
</table>

21,890

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧