1

正如您从下面的代码中看到的那样,我正在尝试执行附加查询。

我在执行第二个查询时遇到问题。似乎代码无法识别第二个查询。有人可以请教吗?

提前致谢。

$query  = "SELECT * FROM tst WHERE status ='active' order by created DESC LIMIT 9";
$result = mysql_query($query);
if (!$result) die  ("database access failed : "  .   mysql_error());

while($row = mysql_fetch_array($result))
{
  echo"<ul class='gallery'><li>";
  echo "<td>" . $row['adid'] . "</td>";
  $subquery = ("SELECT * FROM match_item_image where adid = '.$row['adid'].'  LIMIT 1 ");
  $results = mysql_query($subquery) or die ("Error in query: $subquery " . mysql_error());
  $rows = mysql_fetch_array($results);
  $rows = mysql_num_rows($results);

  echo   '  <a href="viewad.php?adid='.$row['adid'].'&subcat='.$row['subcat'].'">  <img src= "upload/'.$rows['image'].'"height="175" width="200"border="0"  /> </a> ';
  echo "<h2><a href=''>".$row['state'] . "</a></h2>";
  echo   "<h2><a href=''>".$row['loc'] . "</a></h2>";
  echo"
   </li>
 </ul>";
}
4

1 回答 1

4

查询不起作用,因为您在查询中包含$row['adid']了字符串而不是值,请像这样连接它

"SELECT * FROM match_item_image where adid = '" . $row['adid'] . "'  LIMIT 1 "

并且您的查询现在很容易受到攻击SQL Injection,请阅读下面的文章

于 2012-11-13T02:34:01.357 回答