2011-07-27 47 views
0

我有兩個表'p_tuts'和'h_tuts'。我正在使用一種方法來顯示所有返回的行。雖然我不確定如何設置它來運行多個查詢,但我只能讓它一次返回一個查詢。繼承人我的代碼...PHP MYSQL多表查詢

public function QueryAll($my_field, $limit) { 

     $query = mysql_query("SELECT * from $my_field LIMIT $limit"); 
     $rows = array(); 

    while($row = mysql_fetch_array($query)) { 
     $rows[] = $row; 

    } 

    return $rows; } 

這裏是我的索引文件

<?php $results = $Database->QueryAll('p_tuts', 5); ?>  
    <?php foreach ($results as $result): ?> 
      <div class="tutorial"> 
       <div class="tut_header"><h2><a href="view_article_p.php?id=<?php echo $result['id']; ?>" title="<?php echo $result['tut_header']; ?>"><?php echo $result['tut_header']; ?></a></h2></div> 
       <div class="tut_poster">Posted by: <a href="#" title="Adam"><?php echo $result['tut_poster']; ?></a> on <?php echo $result['tut_date']; ?></div> 
       <div class="tut_img rounded"><img src="<?php echo "img_uploads/". $result['tut_img']; ?>" width="180" height="151" /></div> 
       <div class="tut_content"><p><?php $Website->CharLimit($result['tut_content'], 800); ?></p></div> 
      </div> 
      <?php endforeach; ?> 

我真的很想去適應它,所以我可以使用這個類同時顯示多個表,而不僅僅是一個。

親切的問候

回答

0

這是很難不知道這兩個表之間的關係來回答,但它看起來像你需要使用一個JOINUNION

+0

感謝您的輸入我使用了UNION,它工作的很好! :) – user863739