SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2004
    Location
    dublin
    Posts
    2,036
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select Query Problem - Multiple Tables

    Hi all,

    I have 4 database tables. I want to perform a query to loop through each table and display the results under the relevand heading as below.

    At the moment only results from mergers table appears.

    Why is this?

    PHP Code:
      // Perform Query
      $query = "SELECT mergers.id, mergers.name,
                                        rights.id, rights.name,
                                      spin_offs.id, spin_offs.name,
                                      splits.id, splits.name 
                         FROM mergers, rights, spin_offs, splits";
      
      echo $query.'<br /></br >';
      
      $result = mysql_query($query) or die (mysql_error());
      
      echo $result;
      
      
      while(list($id, $name) = mysql_fetch_array($result))
          {
      ?>
              <p>Mergers Table:<br />
          <a href="corporate_actions.php?id=<?=$id;?>"><?=$name;?></a> <br />
              
              <p>Rights Table:<br />
          <a href="corporate_actions.php?id=<?=$id;?>"><?=$name;?></a> <br />
              
              <p>Spin-Offs Table:<br />
          <a href="corporate_actions.php?id=<?=$id;?>"><?=$name;?></a> <br />
      <?        
          
    }
      
    ?>
    Thanks.

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    whoa... you go a lot of problems with that code there!

    but, to strictly answer your question: you have 4 columns called id, and 4 columns called name. how is PHP or mysql supposed to know which one is which?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •