Checking if mysql_query returned anything or not

前端 未结 5 2111
天命终不由人
天命终不由人 2021-02-18 16:56
$query = \"SELECT * FROM `table`\";
$results = mysql_query($query, $connection);

If \'table\' has no rows. whats the easiest way to check for this.?

5条回答
  •  孤独总比滥情好
    2021-02-18 17:31

    If you loop through the results, you can have a counter and check that.

    $x = 1;
    $query = mysql_query("SELECT * FROM table");
    while($row = mysql_fetch_assoc($query))
    {
      $x++;
    }
    if($x == 1)
    {
      //No rows
    }
    

提交回复
热议问题