PDA

View Full Version : Updating timestamp


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.

reefland
Sat 22nd Nov '03, 10:23pm
You know, I sit at this computer for hours trying to figure something out and when I can't, I ask. Inevitabally whenever I post, I figure it out myself within 15 minutes.

Thanks anyways,
Scott Z.

Scott MacVicar
Sat 22nd Nov '03, 11:17pm
your Replace query is "funky" :)

reefland
Sun 23rd Nov '03, 2:11am
Sure, pick on the new coder. :D

Here is what I ended up with and it is working!

$laston = mysql_query("UPDATE laston SET laston=NOW() WHERE lcat_id='$lcat_id' AND userid={$User['userid']}");

Little better? :)
Scott Z.