2011-08-16 35 views
0

我想做出一个条件,如果有结果返回true。我该怎么做?查看MySQL查询是否有结果的条件?

$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> <? 
    } 
} 

感谢

回答

4
if (mysql_num_rows($result) > 0) 
-1

应该有这样的事情:

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