简体   繁体   中英

displaying information from two tables php?

I'm having difficulty displaying some information from MySQL database. I've created a sales page which has a front GRID system which displays adverts and when clicking on each one, you get content with detailings.

I've created two tables within MySQL, one stores all text information, the other displays a series of multiple images link to the ID value. (See below)

Aircraft Sales - Images are stored here

Is there anyway of displaying one of those images instead of getting all displayed within that ID? to populate the grid front image?

You can see all the grid system layout (Fine, but I can't get any images to display), when I do I get all images related to that id.

aeroplanes code.

The code is:

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

Use left join query.

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

Try it

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