reefland
Sat 22nd Nov '03, 10:01pm
I am trying to perform a couple of queries that will check to see if a record exists in the table and if it doesn't, create the row and if it does, update it with the current time. I can get it to create the row if the record doesn't exist but I can't get it to update the time if it does exist. Here's what I have:
if ( $User['userid'] > 0 ) {
$lastonquery = mysql_query("SELECT * FROM laston WHERE lcat_id='$lcat_id' AND userid={$User['userid']}");
$rows = mysql_num_rows($lastonquery);
if ( $rows > 0 ) {
$laston = mysql_query("REPLACE INTO laston WHERE lcat_id='$lcat_id' AND userid={$User['userid']} VALUES($lcat_id,{$User['userid']},NOW())");
}
else {
$laston = mysql_query("INSERT INTO laston VALUES($lcat_id,{$User['userid']},NOW())");
}
}
As mentioned, if the record doesn't exist, it adds it just fine however if the record does exist, the timestamp doesn't change.
Any Ideas?
Thanks,
Scott Z.
if ( $User['userid'] > 0 ) {
$lastonquery = mysql_query("SELECT * FROM laston WHERE lcat_id='$lcat_id' AND userid={$User['userid']}");
$rows = mysql_num_rows($lastonquery);
if ( $rows > 0 ) {
$laston = mysql_query("REPLACE INTO laston WHERE lcat_id='$lcat_id' AND userid={$User['userid']} VALUES($lcat_id,{$User['userid']},NOW())");
}
else {
$laston = mysql_query("INSERT INTO laston VALUES($lcat_id,{$User['userid']},NOW())");
}
}
As mentioned, if the record doesn't exist, it adds it just fine however if the record does exist, the timestamp doesn't change.
Any Ideas?
Thanks,
Scott Z.