2011-08-16 36 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 
}