php drop down menu pulling options from two tables

Discussion in 'PHP' started by xbat, Aug 28, 2013.

  1. #1
    What I am trying to do is take the id from one table and have it match against another table that has the name, then once its matched it will display the name of that table in the drop down list.

    First table has stuff content>>> and a page_id
    Second table has pages info >> which is id the id matches up with the page_id and put pops the name in the drop down..

    Heres a idea of what I have so far... ( Yes I know ths is old code too..) I just really need the idea..

    // this is what will show in the drop down after it has equaled of what is avaiable in the content area..
    mysql_select_db($database_databb_press, $databb_press);
    $query_select_id_name = "SELECT * FROM pages WHERE id=$content_push";
    $select_id_name = mysql_query($query_select_id_name, $databb_press) or die(mysql_error());
    $row_select_id_name = mysql_fetch_assoc($select_id_name);
    $totalRows_select_id_name = mysql_num_rows($select_id_name);
       
    
    
    
    
    
    <select name="select" id="select" onchange="form1.submit()">
          <option value="">Select Page</option>
          <?php
    do { 
       
       
    
       
       
    ?>
          <option value="<?php echo $row_content_data['page_id']?>"><?php echo $row_content_data['page_id']?>
             
           
             
             
              <?php echo $row_select_id_name['page_name']?></option>
         
             
         
     
         
              <?php
    } while ($row_content_data = mysql_fetch_assoc($content_data));
    
      $rows = mysql_num_rows($content_data);
     
      if($rows > 0) {
          mysql_data_seek($content_data, 0);
          $row_content_data = mysql_fetch_assoc($content_data);
      }
    ?>
        </select>
    Code (markup):
     
    Solved! View solution.
    xbat, Aug 28, 2013 IP
  2. #2
    An sql query to get the info from both tables

    $sql = "select table1.page_id, table2.*  from table1, table2 where  id = '.mysql_real_escape_string($content_push).' and table1.page_id = table2.page_id";
    PHP:
     
    t3od0r, Aug 29, 2013 IP
  3. xbat

    xbat Well-Known Member

    Messages:
    326
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Fantastic.. Thank you.. I had to take out the id = '.mysql_real_escape_string($content_push).' and and it worked fine great :)
     
    xbat, Aug 29, 2013 IP