note 57429 added to function.mysql-data-seek
| From: | jaredatbsdcertification dot com at osu1 dot php dot net | Date: | Tue, 04 Oct 2005 02:31:51 +0000 |
| Subject: | note 57429 added to function.mysql-data-seek | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96324@lists.php.net to get a copy of this message | ||
In order to check if a row exists, what is the best function? I am currently using this:
function row_exist($value,$table,$wherecol = 0,$whereval = 0,$dbc,$dbname)
{
mysql_select_db($dbname,$dbc) or die(__FILE__ . " - line: " . __LINE__ . " -
mysql error");
$query = "SELECT $value from $table";
if ($wherecol and $whereval)
{
$query = "$query" . " where $wherecol='$whereval'";
}
$numrows = mysql_num_rows(mysql_query("$query", $dbc));
if ($numrows) return 1;
return 0;
}
This will do what i want, I am just wondering if anyone has simpler, more efficient method they use
for checking for the existence of a row in a table.
----
Manual Page -- http://www.php.net/manual/en/function.mysql-data-seek.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57429
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57429&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57429&report=yes
Search -- http://master.php.net/manage/user-notes.php