douguyi3903 2013-02-23 23:41
浏览 54
已采纳

PHP MYSQL WHERE错误[关闭]

I've got a problem with my php code. The problem is the WHERE clause which is filtering the specified but is also spitting out some error where the 3rd record should be gone. Here's the code:

<body>
<?php
$username="USERNAME";
$password="PASSWORD";
$database="DATABASE";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM searchacts";
$result=mysql_query($query);
$num=mysql_numrows($result);
$result = mysql_query("SELECT * FROM searchacts
WHERE category='Party Bands'");
mysql_close();
?>
<?php
$i=0;
while ($i < $num) {

$image=mysql_result($result,$i,"image");
$name=mysql_result($result,$i,"name");
$category=mysql_result($result,$i,"category");
$description=mysql_result($result,$i,"description");
$stamps=mysql_result($result,$i,"stamps");
$stickmen=mysql_result($result,$i,"stickmen");
$price=mysql_result($result,$i,"price");
$view=mysql_result($result,$i,"view");
$actpagelink=mysql_result($result,$i,"actpagelink");
?>
<a href="<?php echo $actpagelink; ?>" class="searchitem">
<div class="searchimage"><img src="<?php echo $image; ?>"/></div>
<div class="searchtext">
  <div class="searchname"><?php echo $name; ?></div>
  <div class="searchcategory"><?php echo $category; ?></div>
  <div class="searchdescription"><?php echo $description; ?></div>
</div>
<div class="searchstamps"><img src="<?php echo $stamps; ?>" /></div>
<div class="searchstickmen"><img src="<?php echo $stickmen; ?>" /></div>
<div class="searchprice"><span class="pricefrom">from</span><?php echo $price; ?></div>
<div class="searchview"><img src="<?php echo $view; ?>" /></div>
</a>
<?php
$i++;
}
?>
</body>

Its probably something very simple, This is the error:

Warning: mysql_result() [function.mysql-result]: Unable to jump to row 2 on MySQL result index 3 in /home/enterta1/public_html/searchtestingv1.php on line 31

Which goes on for a number of lines

  • 写回答

4条回答 默认 最新

  • dongqiang8058 2013-02-24 00:08
    关注

    Your $num counts all the fetched sets/rows in the following statement:

    SELECT * FROM searchacts
    

    while, you're trying to output data only for a selected few of them:

    SELECT * FROM searchacts WHERE category='Party Bands'
    

    Since, the second query always results in rows less than or equal to the first one; you get that error.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制