PDA

Click to See Complete Forum and Search --> : When Insert .. but what when Update ?


prokhaled
Jun 26th, 2002, 03:41 AM
In this code:
$Sql = "INSERT INTO Subject (ReplyNo) VALUES ('0')";
$Result = mysql_query($Sql);
Echo mysql_insert_id();

I use ( Echo mysql_insert_id(); ) to echo the the current ID that Inserted

but what can I use to know the current ID that updated ??

I try that
$Sql = "UPDATE Main SET tt='$tt' WHERE MainID=$MainID";
$Result = mysql_query($Sql);
Echo mysql_update_id();

but give me error that (there is not any function like that (mysql_update_id();)

TheGoldenShogun
Jun 26th, 2002, 05:44 AM
I'm not sure there is a function for that. There is a function mysql_affected_rows() which returns how many records were updated/deleted. If you were doing an update with just one record, you could make sure it went through alright, you could use this to check it.

prokhaled
Jun 26th, 2002, 09:30 AM
Thank you too much TheGoldenShogun !! that is what I need..

filburt1
Jul 1st, 2002, 08:39 PM
Also, if you don't want to add a duplicate row, you can use:

REPLACE table...

Iamryan2002
Jul 1st, 2002, 09:53 PM
I would honestly do it like this:


$query = "SELECT * FROM table";
$result = mysql_query($query, $connect);

while($curr_id = mysql_fetch_array($result))
{
$id_count = $cur_id[id]; // This is the long way...
}
// $id_count is equal to the last id in the db!

filburt1
Jul 1st, 2002, 09:56 PM
How about:

SELECT id FROM table ORDER BY id ASC LIMIT 1

Iamryan2002
Jul 1st, 2002, 09:58 PM
that would work also, I like to take all my data out, because I usually it...