Page 1 of 1
check for duplicate record
Posted: Wed Mar 24, 2004 2:53 am
by crimsonluv
is it possible for me to check duplicate record using mysql_fetch_object instead of mysql_fetch_array?
$dbquery = "SELECT * FROM Staffs_Category";
$result = mysql_query($dbquery, $dblink);
while($row = mysql_fetch_object($result)){
$limit = count($row);
}
for($i = 0; $i<limit; $i++) {
if($row == $staffcat || $row == $other) {
echo 'category entered is already in record. please re enter';
}
}
any mistake here?
Posted: Wed Mar 24, 2004 3:25 am
by markl999
Not really a good idea to select all the rows just to see if one exists. Might be better to do a query like ,
SELECT COUNT(*) FROM Staffs_Category WHERE cat='$staffcat' .. then use mysql_num_rows() to see if any rows were returned, if there were then you know it's a duplicate.
Posted: Wed Mar 24, 2004 9:53 am
by Steveo31
I had a similar problem...
viewtopic.php?t=19442
Posted: Wed Mar 24, 2004 12:47 pm
by malcolmboston
<-- what i always do
Code: Select all
require ("dbhandler.php");
$dbquery = "SELECT something FROM somewhere WHERE username = $username";
$result = mysql_query($dbquery) or die (mysql_error());
$resultarray = mysql_fetch_array($result, MYSQL_ASSOC);
$affected = mysql_num_rows($result);
// query complete
// now lets check for a previous match
if ($affected >= 1)
{
// there is already a match in the database
// do something
exit();
}
else
{
// continue, the username wasnt already in the database
}
dunno whether this is good or bad but its the way i always do it and it works
mal
Posted: Wed Mar 24, 2004 7:27 pm
by crimsonluv
thanks for your reply
i'll try again and see what happen
thanks a lot!