How to Take an Auto Increment Id and Attach it to a Variable in the same Index

Asked

Viewed 485 times

1

How to Grab a newly created auto increment id and repeat it in another column by attaching it to a variable?

 Ex: Na hora do Insert pego idxxxx  repito somando a $varxxxx


  date_default_timezone_set('UTC');
  while (strtotime($start) <= strtotime($data_fim)) { // pega a data de inicio e a   
  data fim e faz o loop inserindo no mysql

  $sql = mysql_query ("INSERT INTO agenda_saidas(nome,url)
  VALUES('nome','agendados_ver.php?id=$varxxxxxx')",
  $conexao) or die( mysql_error());

1 answer

2


As far as I know, this is not possible. You need to first do the INSERT, and then a UPDATE:

UPDATE agenda_saidas
SET url = CONCAT(url, id)
WHERE id = LAST_INSERT_ID()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.