显示来自两个表php的信息?

时间:2015-10-26 16:52:33

标签: php mysql

我很难从MySQL数据库中显示一些信息。我创建了一个销售页面,它有一个显示广告的前GRID系统,当点击每个广告时,你会得到详细内容。

我在MySQL中创建了两个表,一个存储了所有文本信息,另一个显示了一系列多个图像链接到ID值。 (见下文)

here

无论如何显示其中一张图片而不是全部显示在该ID内?填充网格前端图像?

Aircraft Sales - Images are stored here

飞机代码。

代码是:

<div id="home" class="main-container">
  <div class="content-container">
    <div class="container">
      <div class="bs-example" data-example-id="thumbnails-with-custom-content">
        <h1 style="text-align:left;"><font color="#D60808">Aero-Agent</font>
        <small><font color="#909090">Current Stock List</small></font></h1>
        <?php
           // connect to database + run query to grab all aircraft in database.
           /*
           include_once('dbconnection.php');
            $str = "SELECT * FROM `aircraftsales`";
            $rs = mysql_query($str);
              if(!$rs )
              {
                die('Could not get data: ' . mysql_error());
              }
            if (mysql_num_rows($rs) == 0)
               echo '<h4><font color="#909090">No current aircraft for sale.</font></h2>';
             else {
               while($row = mysql_fetch_assoc($rs)) {
             */
            include_once('dbconnection.php');
            $str="SELECT * FROM `aircraftsales`";
            $rs = mysql_query($str);
            if(!$rs )
            {
              die('Could not get data: ' . mysql_error());
            }

            $imagesstr="SELECT * FROM `aircraftimages`";
            $imagesrs = mysql_query($imagesstr);
            if(!$imagesrs )
            {
              die('Could not get data: ' . mysql_error());
            }
            while($row = mysql_fetch_assoc($rs)) {
            ?>
            <div class="vehicle-blob list FORSALE">
              <a href="/content.php?id=<?php echo $row['id']?>"><div class="vehicle-photo photo-list selected">
                <img src="exam/upload/aircraftsales/<?php echo $imagerow['image'];?>" /></di
                  <div class="status-graphic"></div>
                    <div class="overlay list">
                      <div class="inner-tube">
                      <h1><?php echo $row['title']?> <?php echo $img;?> <br /><font color="#D60808"><b>&pound;<?php echo $row['price']?></b></font></h1>
                  </div>
                </div>
              </a>
              <?php
              }
              ?>
          </div>
      </div>
    </div>
</div>


<?php include_once('ppls_css/includes/ppl-footer.php'); ?>

1 个答案:

答案 0 :(得分:0)

使用左连接查询。

  

SELECT * FROM aircraftsales left join aircraftimages on aircraftsales.aircraft_id = aircraftimages.aircraft_id

试试吧