2016-03-30 13 views
0

同じ$ cidと$ tidを持つテーブル・ポストからすべての行をフェッチしようとしたとき、results2問合せでエコーされた表内にこれらの値を持つ行が1つしか表示されないときは、while文複数の行を見つけ、各行に対して新しいテーブルを作成します。どんな助けも大歓迎です。一致する行の抽出| 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
$result2= $con->query("SELECT * FROM posts WHERE cat_id='".$cid."' AND topic_id='".$tid."' **LIMIT 1**"); 

LIMIT 1を削除し、またはより大きな数

に設定
関連する問題