我试图从具有相同$ cid和$ tid的表帖中获取所有行,此时results2查询仅显示在一个回显表中具有这些值的一行,我想让我的while语句找到多行,每行创建一个新表。任何帮助都会非常受欢迎。
// table topic also contains same value as $cid and $tid
$result= $con->query("SELECT * FROM topic WHERE cat_id='".$cid."' AND id='".$tid."' LIMIT 1");
if($result->num_rows ==1 ) {
// start of table to echo out
echo "<table width='100%'>";
while($row = $result->fetch_assoc()){
// I would like this query to return all rows that have same values $cid $tid
$result2= $con->query("SELECT * FROM posts WHERE cat_id='".$cid."' AND topic_id='".$tid."' LIMIT 1");
//condition to check if row meets result2
while($row2 = $result2->fetch_assoc()){
//generate a table a populate it with the results if more than one row is found with same result create another table
// echo table rows and populate it with results
echo "<tr><td valign='top' style='border: 1px solid #000000;'><div style='min-height: 125px;'>".$row['topic_title']."<br />by ".$row2['post_content']." - ".$row2['p_date']."<hr /><br />".$row2['post_creater']."</div></td><td width='200' valign='top' align='center' style='border: 1px solid #000000;'>User Info Here</td>
</tr><tr><td colspan='2'><hr /></td></tr>";
}
}
}
答案 0 :(得分:0)
$result2= $con->query("SELECT * FROM posts WHERE cat_id='".$cid."' AND topic_id='".$tid."' **LIMIT 1**");
删除LIMIT 1并将其设置为更大的数字