-1
I have a database with a table called products, in this table I have 3 columns:
name | category | url |
---|
With the code below I can copy all the data of an existing product to a new product.
$id = 33;
$sql = "INSERT INTO produtos (nome,categoria,url) SELECT nome,categoria,url FROM produtos WHERE id=:id";
$sql = $pdo->prepare($sql);
$sql->bindValue(":id",$id);
$sql->execute();
There’s only one problem: every product must have one url
different, so my idea is to generate a url for each product, for example:
$url = 'produto'.rand(1.100);
But I have no idea how to do this with the above code. I made the following attempt:
$sql = "INSERT INTO produtos (nome,categoria,url) SELECT nome,categoria,url=".$url." FROM produtos WHERE id=:id";
$sql = $pdo->prepare($sql);
$sql->bindValue(":id",$id);
$sql->execute()
But it didn’t work, the product wasn’t even copied.
I don’t think I could do that with that code?