我想将图像与firstname,lastname相关联...如何检索最后一行并使用它插入另一个表?我试过$image = $mysqli->insert_id;然后绑定但它不起作用.有人可以帮我吗?
$image = $mysqli->insert_id;//this should come from table2
$stmt = $mysqli->prepare("
insert into table1 (username, firstname, lastname, image)
select ?,?,?,image from table2 t2 where username = ? and t2.id = ?
");
$stmt->bind_param('sssss', $username, $fname, $lname, $username, $image);
$stmt->execute();
Run Code Online (Sandbox Code Playgroud) 我试图用where子句选择两个表,
问题:我得到的结果超过2.像123451111我只有两个值为1的ID.我想我做错了.
这些表格没有相同的结构,也没有任何关联.有任何想法吗?
<?php include_once("config.php");
$s = '1';
$stmt =$mydb->prepare("select * FROM table1,table2 where table1.id = ? or table2.id = ?");
stmt->bind_param('ss', $s, $s);
echo $mydb->error;
$stmt->execute();
?>
<?php
$results = $stmt->get_result();
while ($row = $results->fetch_assoc()) {
echo $row['id']."<br/>";
}
?>
Run Code Online (Sandbox Code Playgroud)