hi to all
a have something like
$query = "INSERT INTO somewhere VALUES ('', '$IT', '0', '10', '$F0', '$F1', '$F2', '$T', NOW(), '$U', '$P', '0', NOW(), '??????')";
where the ????? are i need something to get the same value as the '' in the first position which is an autoincremented id how to do it ?
woud by nice to do it whit out and extra query like
SELECT MAX(id) FROM somewhere; and then put this value in it (+1)
mmm..pi..3.14..
06-29-2005, 04:12 AM
First, your syntax is a bit off. It should look more like this:
$query = "INSERT INTO somewhere (column1, column2, column3, column4, column5, column6, column7, column8, column9, column0, column11, column12, column13, column14) VALUES('', '$IT', '0', '10', '$F0', '$F1', '$F2', '$T', NOW(), '$U', '$P', '0', NOW(), '??????')";
You need to specify the column where each piece of information in the values will be placed according to my knowledge of SQL.
As far as duplicating the same value that appears in the auto increment, I don't know if that's possible with just one query, you might have to do it in 2 separate queries, like this...
//leave out the last column, and just insert the rest of the data first
$query = mysql_query("INSERT INTO somewhere (column1, column2, column3, column4, column5, column6, column7, column8, column9, column0, column11, column12, column13) VALUES('', '$IT', '0', '10', '$F0', '$F1', '$F2', '$T', NOW(), '$U', '$P', '0', NOW())") or die(mysql_error());
//now retrieve the auto incremented value, increase by 1, and insert it into the last column
//now get the number that was just auto incremented and increase by 1, store it as a var to be inserted
$result = mysql_query("SELECT column1 FROM myTable") or die(mysql_error());
$Row = mysql_fetch_array($result);
$newnum = $Row[0]+1;
$query = mysql_query("INSERT INTO somewhere(column14) VALUES('" . $newnum . "')") or die(mysql_error());
I have no idea if that will work, but it's worth a shot ;)
Eric
You need to specify the column where each piece of information in the values will be placed according to my knowledge of SQL.
Hmmm the syntax from me is working :P
i get errors as fare i change the number of colums in the DB and not in the syntax
i was just hoping to prevent the 2. query
$query = "SELECT MAX(id) FROM somewhere";
include $P_DB;
$ID = mysql_result($result,0)+1;
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.