作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 个表 question_details
和 paid_response
question_details
包含
qno qshortcode
504 what do you want
515 what is your name
541 what is your address
.
.
other.. others question
paid_response
包含
qno paid_respo paid_rev sys_date
504 yes 0.60 2014-12-16 04:14:40
515 no 0.42 2014-12-17 04:14:40
现在我想要来自 question_details
的 qshortcode
以及给定的 qno(504 和 515)
以及来自 paid_response
表的paid_respo其中 pay_rev not=0.00 并且在两个日期之间
what do you want what is your name //fetching from `question_details` table
yes no //fetching from `paid_response` table with respect to `qno` where paid_rev not 0.00
我的代码用于从question_details`表中获取qshortcode
<?php
//DB connection goes here
$query=mysql_query("select qshortcode from question_details where qno=504 or qno='515'");
echo '<tr>';
for($i = 0; $row = mysql_fetch_array($query);$i++) {
echo '<td>'.$row['qshortcode'].'</td>';
echo '</tr>';
} ?>
它的抓取就像
what do you want what is your name
//cant fetch paid_respo of specific qshortcode below this where paid_rev not euqals to 0.00 or blank
最佳答案
尝试使用这个:使用联接来合并两个表
<?php
//DB connection goes here
$query=mysql_query("select qshortcode,paid_respo from question_details left join paid_response on paid_response.qno=question_details.qno where question_details.qno in (504,515)");
echo '<table>';
while ($row = mysql_fetch_array($query)) {
echo '<tr>';//to show each response as one row.
echo '<td>'.$row['qshortcode'].'</td>';//what do you want
echo '<td>'.$row['paid_respo'].'</td>';//yes
echo '</tr>';
}
echo '</table>'
?>
关于php - 如何从 mysql 获取行到表头以及与获取的表头相关的特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27604080/
我是一名优秀的程序员,十分优秀!