简体   繁体   中英

PHP MYSQL Multiple table query

I have two tables 'p_tuts' and 'h_tuts'. I'm using a method to display all the returned rows. Although I'm not sure how to set it up to run multiple queries, I can only get it to return one query at a time. Heres my code...

   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;   }

Here is my index file

 <?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; ?>

I'd really like to adapt it so I can use this class to display both multiple tables, rather than just the one.

kind regards

如果不知道两个表之间的关系,很难回答这个问题,但是看起来您需要使用JOINUNION

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM