Page 1 of 1

me again!! gettin the last row in a table

Posted: Wed May 07, 2003 9:55 am
by gasoga
hi!

I have a piece of code that works properly if i use it in the query analyseer but when i use it in my code it doesnt work!

I want it to take the last call id just entered and unsert it into another table!
It will work for the very first row but then every row inserte dinto that table after has the exact same value!!!

Code: Select all

<?php
$Q03 = "INSERT INTO $dblog VALUES('$emp_username','$cust_username','$company_name','$date','$time','$call_type','$description','$priority','$res_call_imm','$solution','$assigned_to','$resolved','$solution2','$call_closed_date')";
$R03 =  odbc_exec($db,$Q03) or die("Bad Q03:".mysql_error()); 
 
$Q93 = "SELECT TOP 1 Call_ID from calls_logged order by Call_ID desc; ";
$R93 = odbc_exec($db,$Q93) or die("Bad Q93:".mysql_error());
$result = odbc_fetch_into($R93,$A93);

$Q73 = "INSERT INTO 
$dbcall_log
VALUES('$result','$emp_username','$cust_username','$date')";
$R73 =  odbc_exec($db,$Q73) or die("Bad Q03:".mysql_error());
odbc_free_result($R73);


?>

Code: Select all

Table one

Call_ID
1
2
3
4

Table two
1
1
1
1
Any ideas would be great thanx!!

Posted: Thu May 08, 2003 5:17 am
by Wayne
try

Code: Select all

$Q93 = "SELECT MAX(Call_ID) from calls_logged order by Call_ID";
or if Call_ID is an auto increment column you can get the Call_ID value by using

mysql_insert_id directly after the original insert statement.

Posted: Thu May 08, 2003 6:20 am
by twigletmac
Which database are you using?

Mac

Posted: Thu May 08, 2003 7:13 am
by Wayne
good point mac, sorry I missed that!

why are you using odbc calls and mysql_error() ????

Posted: Thu May 08, 2003 11:29 am
by gasoga
sorry forgot to say!! its an mssql database!!

Im new to using odbc and odbc_error doesnt not work for me!
However the mysql error message does???!!!!!!
Strange!