您的位置:首页 > 编程语言 > PHP开发

如何用PHP判断数据库中的记录是否存在

2012-09-21 14:52 543 查看
以下是代码片段:

<?php

require_once('db.platform.inc');

$gid=100;

$task='setup';

$status='A';

$sql="select * from checklist where game_id=$gid and task='$task' and status='$status'";

$result=mysql_query($sql);

/*if (!$result) { // add this check.

echo "record doesn't exists";

die('Invalid query: ' . mysql_error());

}

else

{

echo "record exists!!!";

}

*/

$row = mysql_fetch_array($result, MYSQL_ASSOC);

// if (empty($row['game_id']))

if (!mysql_num_rows($result))

{

echo "record doesn't exist~~~~~!!!!!!";

}

else

{

// echo mysql_num_rows($result)."\n";

echo $row['game_id'];

echo $row['task'];

}

?>

本文出自 “安家圈子交流学习” 博客,请务必保留此出处http://brucetam.blog.51cto.com/1863614/1001759
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: