普通网友
2013-07-30 04:58
浏览 103
已采纳

SELECT * FROM有两个不同的表[重复]

This question already has an answer here:

I've been fiddling with this for bit and tried a couple different ways to combine both SELECT FROM statements, but I can't get it to work where I can call on fields from two tables within the same database. It works find if I remove either one. I tried to combine them using UNION (not sure if that's the correct thing), but couldn't get it to work.

Here's what I got so far with them separated:

$id = $_POST['id'];

$edit = $db->prepare("SELECT * FROM contacts WHERE id = (?)");
$edit->bind_param('s', $id);
$edit->execute();
$edit->bind_result($id, $firstName, $lastName, $email, $phone, $category);

$categories = $db->prepare("SELECT * FROM category");
$categories->execute();
$categories->bind_result($cateid, $setcategory);

echo $firstName;

while ($categories->fetch()) {
    echo $setcategory;
}

I'm new to all of this. I'd be grateful if someone could point me in the right direction. Thanks!

</div>

2条回答 默认 最新

相关推荐 更多相似问题