查看MySQL查询是否有结果的条件?

时间:2011-08-16 06:57:33

标签: mysql

我想创建一个条件,如果有结果则返回true。我该怎么做?

$result = mysql_query("SELECT * FROM `Groups` WHERE `City` = '$city2' LIMIT 12 OFFSET 6");


if (the condition) {

while($row = mysql_fetch_array( $result )) { ?>
    <a href="/?ciudad=<?php echo $city; ?>&colegio=<?php echo $row['Group']; ?>" class="<?php if ($group == $row['Group']) { echo "selected"; } ?>"><?php echo $row['Group']; ?></a>  <?
    }   
}

由于

2 个答案:

答案 0 :(得分:4)

if (mysql_num_rows($result) > 0)

答案 1 :(得分:-1)

应该有类似的东西:

if ($result.size > 0) {
  // do this
}