MySQL直接提供结果,但没有通过脚本

时间:2013-09-02 13:46:35

标签: php mysql

我正在编写脚本,在此代码部分中从MySQL服务器检索信息但是:

正在执行的命令:

通过此代码执行命令,不会产生任何结果:

$zapytanie = "SELECT * FROM all_orders WHERE (ID = '2' OR ID = '3' OR ID = '5' OR ID = '7' OR ID = '9' OR ID = '10' OR ID = '11' OR ID = '15' OR ID = '17' OR ID = '18' OR ID = '19' OR ID = '22' OR ID = '24' OR ID = '25' OR ID = '26' OR ID = '27' OR ID = '28' OR ID = '29' OR ID = '30' OR ID = '31' OR ID = '32' OR ID = '35' OR ID = '36' OR ID = '37' OR ID = '38' OR ID = '39' OR ID = '40' OR ID = '41' OR ID = '45' OR ID = '47' OR ID = '48' OR ID = '49' OR ID = '50' OR ID = '53' OR ID = '54' OR ID = '55' OR ID = '56' OR ID = '57' OR ID = '60' OR ID = '61' OR ID = '62' OR ID = '63' OR ID = '64' OR ID = '65' OR ID = '67' OR ID = '68' OR ID = '69' OR ID = '70' OR ID = '71' OR ID = '72' OR ID = '73' OR ID = '74' OR ID = '75' OR ID = '76' OR ID = '81' OR ID = '82') AND status='sent' ORDER BY ID ASC";

$validate = mysqli_query($con,$zapytanie);
  while($row = mysqli_fetch_array($validate)) {
    $array[$i] = $row[ID];
    $i++;
  }
  print_r($array, true);

直接执行结果 - 1行:

http://fotteria.pl/uploads/gallery/0/0/ec46b7/319df40409.jpg

我真的不知道那里发生了什么,但是你可以看到我可以通过这个命令直接检索结果,但是在使用这段代码时没有结果。

3 个答案:

答案 0 :(得分:4)

print_r($array, true);

是你的问题

$zapytanie = "SELECT IN FROM all_orders WHERE ID IN(2,3,5...) AND status='sent' 
              ORDER BY ID ASC";
$array = array();
$result = mysqli_query($con,$zapytanie);
while($row = mysqli_fetch_array($result)) {
    $array[] = $row['ID'];
}
print_r($array);

答案 1 :(得分:0)

我认为有两个问题:

  1. $ row [ID]应为$ row ['ID'],因为ID不是数值。
  2. print_r中的“true”表示print_r不会输出任何内容,只返回结果。

答案 2 :(得分:-1)

只是也许这是一个选择:

$result = mysqli_query($con,"SELECT * FROM all_orders");

echo "<table border='0'>
<tr>
<th> ( enter variable here) </th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['( enter variable here) '] . "</td>";
  echo '<td><input type="hidden" class="entryid" name="id" value='.$row['ID'].'
  echo "</tr>";
  }
echo "</table>";


mysqli_close($con);

这不一定更好,因为我不通过ID(自动增量)查找,但它对我有用!