Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确定是否不返回任何内容。。PHP-MySQL_Php_Html_Mysql_Html Table - Fatal编程技术网

确定是否不返回任何内容。。PHP-MySQL

确定是否不返回任何内容。。PHP-MySQL,php,html,mysql,html-table,Php,Html,Mysql,Html Table,我有以下代码: <table> <thead> <tr> <th>Service</th> <th>Status</th> </tr> </thead> <?php $result = mysql_query("SELECT Service, Status FROM services WHERE Company='Company 1'"); while (

我有以下代码:

<table>
<thead>
  <tr>
    <th>Service</th>
    <th>Status</th>
  </tr>
</thead>
<?php $result = mysql_query("SELECT Service, Status FROM services WHERE Company='Company 1'");
  while ($row = mysql_fetch_array($result)) {
          //  ^ must be a single '=' !!!!
      echo '<tr><td>' . $row["Service"] . '</td>';
      echo '<td>' . $row["Status"] . '</td></tr>';
  } ?>
</table>

服务
地位

在我看来,最好的方法是if语句+do/while循环:

$result = mysql_query("your query");

if ($row = mysql_fetch_array($result)) {
    do {
        // your loop stuff
    } while ($row = mysql_fetch_array($result));
} else {
    echo "No result";
}
您也可以使用mysql_num_rows函数,但请记住,pdoapi没有此类函数,do/while解决方案可以与任何API一起使用


另外,如果只使用数组的关联部分,请使用mysql_fetch_assoc而不是mysql_fetch_数组。

在我看来,最好的方法是If语句+do/while循环:

$result = mysql_query("your query");

if ($row = mysql_fetch_array($result)) {
    do {
        // your loop stuff
    } while ($row = mysql_fetch_array($result));
} else {
    echo "No result";
}
您也可以使用mysql_num_rows函数,但请记住,pdoapi没有此类函数,do/while解决方案可以与任何API一起使用

另外,如果您只使用数组的关联部分,请使用mysql\u fetch\u assoc而不是mysql\u fetch\u数组。

您可以使用以下函数:

$result = mysql_query("SELECT Service ... ");

if (mysql_num_rows($result) > 0) {
   // Display Results
}
else {
   // No Results
}
您可以使用以下功能:

$result = mysql_query("SELECT Service ... ");

if (mysql_num_rows($result) > 0) {
   // Display Results
}
else {
   // No Results
}

天哪,我总是使用mysql\u num\u行,但这段代码更干净+1我真的很想知道为什么我的帖子被否决,这一直是我在PDO中使用的解决方案,如果有人知道得更好,我也想知道!天哪,我总是使用mysql\u num\u行,但这段代码更干净+1我真的很想知道为什么我的帖子被否决,这一直是我在PDO中使用的解决方案,如果有人知道得更好,我也想知道!甚至
if(mysql\u num\u rows($result))
(失败时也返回
FALSE
),甚至
if(mysql\u num\u rows($result))
(失败时也返回
FALSE