检查mysql中是否已存在行

quick question:

How to check if row already exists in mysql?

I know some will suggest mysql_num_rows(), which I've tried and no good.

Here's the PHP code:

...

$chk = mysql_query("SELECT * FROM f_table WHERE f = '$id' AND h = 'h' AND status = '1'");

if(mysql_num_rows($chk) > 0){
    $msg = 'exist';
}else{
            $msg = 'gotta';
    }

Ps: I just noticed that the php manual suggested us to use some else instead of 'mysql_num_rows()', and my mysql version is 5.0. Is it related?

Thank u for ur time.

Typically you'd want to let MySQL do the counting instead of fetching all rows. MySQL can use indexes and doesn't have to retrieve all data, which may be a lot more efficient:

$result = mysql_query('SELECT COUNT(*) as `count` FROM ...') /* or die(mysql_error()) */;
$row = mysql_fetch_assoc($result);

if ($row['count'] ...)

If you're not going to use the rows, just do a SELECT COUNT(*) FROM .... Otherwise, mysql_num_rows should work, even if this API is deprecated.