要从 1 个表中选择数据,我使用以下代码:
if(isset($UserID)) {
$users = $con->prepare("
SELECT DISTINCT
d.FirstName
,d.LastName
,d.Picture
FROM Details d
WHERE d.UserId = ?
");
$users->bind_param('i', $GetUserId);
$users->execute();
$users->bind_result(
$FirstName,
$LastName,
$Picture
);
} else {
echo "There is no User ID detected, try to refresh browser.";
}
while ($users->fetch()) { ?>
<div class="grid-group">
<span>Personal Details</span>
<div class="grid-column">
<div class="grid-item header">First Name </div>
<div class="grid-item header">Last Name </div>
<div class="grid-item header">Picture </div>
</div>
<div class="grid-column">
<div class="grid-item"><?php echo $FirstName; ?></div>
<div class="grid-item"><?php echo $LastName; ?></div>
<div class="grid-item"><?php echo $Picture; ?></div>
</div>
</div>
<?php } ?>
如何添加 1 个查询以从另一个表中选择一些数据?就像是:
SELECT Foo, Bar, FooBar
FROM Bizz
WHERE UserId = ?
我应该使用mysqli_multi_query
吗?但是我怎样才能使用它和bind_result
它之后呢?我无法实现正确的语法。或者还有其他方法吗?
我将需要从这样的 2 个表中打印数据:
while ($users->fetch()) { ?>
<div class="grid-group">
<span>Personal Details</span>
<div class="grid-column">
<div class="grid-item header">First Name </div>
<div class="grid-item header">Last Name </div>
<div class="grid-item header">Picture </div>
</div>
<div class="grid-column">
<div class="grid-item"><?php echo $FirstName; ?></div>
<div class="grid-item"><?php echo $LastName; ?></div>
<div class="grid-item"><?php echo $Picture; ?></div>
</div>
</div>
<div class="grid-group">
<span>Foo Bar</span>
<div class="grid-column">
<div class="grid-item header">Foo </div>
<div class="grid-item header">Bar </div>
<div class="grid-item header">FooBar </div>
</div>
<div class="grid-column">
<div class="grid-item"><?php echo $Foo; ?></div>
<div class="grid-item"><?php echo $Bar; ?></div>
<div class="grid-item"><?php echo $FooBar; ?></div>
</div>
</div>
<?php } ?>
由于某些原因,我无法使用JOINS
. 你有什么想法吗?
更新
如果我在下面准备 2 个查询,我会得到空白屏幕:
if(isset($UserID)) {
$users = $con->prepare("
SELECT DISTINCT
d.FirstName
,d.LastName
,d.Picture
FROM Details
WHERE d.UserId = ?
");
$users->bind_param('i', $GetUserId);
$users->execute();
$users->bind_result(
$FirstName,
$LastName,
$Picture
);
$users2 = $con->prepare("
SELECT DISTINCT
Foo
, Bar
, FooBar
FROM Bizz
WHERE UserId = ?
");
$users2->bind_param('i', $GetUserId);
$users2->execute();
$users2->bind_result(
$Foo,
$Bar,
$FooBar
);
} else {
echo "There is no User ID detected, try to refresh browser.";
}
while ($users->fetch()) { ?>
...
你有什么想法吗?