-3

也许我在混合苹果和橘子——$clist 是一个带有 csv 的字符串。我无法让 $row2['$cat'] 回显任何内容。提前致谢

$cats = explode(",", $clist);
foreach($cats as $cat) {
  $cat = trim($cat);
  $q = "SELECT * FROM contacts WHERE id = '$cat' ";
  $result = mysql_query($q, $link);

  $num2=mysql_num_rows($result2);

  $x = 0;
  while($x < $num2) {
    $row2 = mysql_fetch_array($result2);
    echo $row2['$cat'];
    $x++;
  }
}
4

2 回答 2

2

来自 Michael Berkowski 的评论:删除引号。$row2[$cat]

于 2013-01-15T02:18:51.823 回答
0

与其对数组中的每个值进行查询,不如只进行一次查询?

$cats = array('ginger','tabby','somthing');
$sql = "SELECT * FROM contacts WHERE id IN(\"".implode('", "',$cats)."\")";

//SELECT * FROM contacts WHERE id IN("ginger", "tabby", "somthing")
于 2013-01-15T02:39:35.160 回答