如何同时运行这两个查询?
更新的 PHP
<?php
$result = $sth->fetchAll();
print_r($result); //or var_dump($result); for more info
foreach($result as $row){
print_r($row);
}
?>
在 SQL 视图上:
$pdo = new PDO($h1, $u, $p);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $pdo->prepare('
SELECT uFName, uLName, listTitle, listPropPrice, listCmt, listDt
FROM User U, Listing L
WHERE U.uID = L.uID
;');
$sth->execute(array());
#GET Merchant (Seller) Info and Listings Offered On
$pdo2 = new PDO($h1, $u, $p);
$pdo2->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth2 = $pdo2->prepare('
SELECT mFName, mLName, moAmt, moDtOff
FROM Merchant M, MerchantOffer MO, Listing L
WHERE M.mID = MO.mID
AND L.listID = MO.listID
;');
$sth2->execute(array());
如何在同一个 中运行
语句?$sth
和 $sth2
WHILE
模式
Louis 代码的输出:
UPDATED PHP
<?php
$result = $sth->fetchAll();
print_r($result); //or var_dump($result); for more info
foreach($result as $row){
print_r($row);
}
?>
On the SQL View:
$pdo = new PDO($h1, $u, $p);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $pdo->prepare('
SELECT uFName, uLName, listTitle, listPropPrice, listCmt, listDt
FROM User U, Listing L
WHERE U.uID = L.uID
;');
$sth->execute(array());
#GET Merchant (Seller) Info and Listings Offered On
$pdo2 = new PDO($h1, $u, $p);
$pdo2->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth2 = $pdo2->prepare('
SELECT mFName, mLName, moAmt, moDtOff
FROM Merchant M, MerchantOffer MO, Listing L
WHERE M.mID = MO.mID
AND L.listID = MO.listID
;');
$sth2->execute(array());
How do I run $sth
and $sth2
within the same WHILE
STATEMENT?
SCHEMA
Output of Louis Code:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不必同时运行查询。
事实上,从数据库获取数据与创建 HTML 无关(或者应该)。它的任务不同。
因此,首先将数据放入数组中,然后以您希望的任何方式打印出来 - 同时或方格。
you don't have to run your queries simultaneously.
As a matter of fact, getting data from database has (or should be) nothing to do with creating HTML. Its different tasks.
So, get your data into array(s) first and then print it out in whatever manner you wish - simultaneously or checkered.
我认为您正在寻找的是 fetchAll 语句,然后您有一个在使用另一个 while 的同时迭代的结果数组。 (您需要跟踪一个单独的计数器)
更新:
现在我明白了,试试这个。
I think what you're looking for is the fetchAll statement, you then have a result array to iterate through at the same time of using the other while. (you'll need to keep track of a separate counter)
UPDATE:
Now I get ya, try this.
我更新了路易斯代码,因为我认为它可以更好地处理。
变化是:
我无法发表评论,因为我已经做出了新答案,而不是评论或编辑路易斯答案。
I have update Louis code because I think it can better handle.
The changes are:
I can't comment, because it I have made a new answer instead of comment or edit Louis answer.