How to connect 2 tables in mysql?

Discussion in 'PHP' started by Alice24, Oct 10, 2011.

  1. #1
    i have 2 tables in mysql and i want to extract a variable from one table and with this variable to extract other things in the table nr 2
    for example:


    
    
    require_once('config.php');
    $result = mysql_query("SELECT * FROM tpb ORDER BY id DESC ");
    
      
    while($row = mysql_fetch_array($result))
     {
          /* Get data from tpb table and get them into variables. */
            
            $tipfilm=$row['hd']; 
            $ebay=$row['idfilm'];	
            $adresa=$row['adresa'];
            $nume=$row['nume'];
            $data=$row['data'];
            $size=$row['size']; 
            $by=$row['by'];
            $size=$row['size'];  
            $downloads=$row['downloads'];    
            $thanks=$row['thanks']; 
          }  
           
            $sql = mysql_query("SELECT * FROM filme WHERE id='$ebay'  ");
    	     while($bbb = mysql_fetch_array($sql))
     
    
      {
    
    /* Get data from filme table and put them into variables. */
    $youtube=$bbb['youtube'];
    $poza=$bbb['poza'];
    $imdb=$bbb['imdb'];
    $subtitrare=$bbb['download'];
    }
      
     
    $sss = mysql_query("SELECT * FROM tpb ORDER BY id DESC ");
    
     while($doit = mysql_fetch_array($sss))
     {
     
      echo"
     <table border=0 WIDTH=100%>
      <tr>
        <td >
         <p>Tip Film: <br> " . $doit['hd'] . "  </p> </td> <td><a target='_blank' href=" . $youtube . " ><img  height='20' width='40' src='http://www.esubtitrari.tv/youtube.jpg' title=' Trailer Youtube '/>   <br> <a target='_blank' href=" . $imdb . " ><img  height='20' width='40' src='http://www.esubtitrari.tv/imdb.jpg' title=' IMDB '/> </a>  </td><td> <img  height='50' width='50' src=" . $poza . " title=" . $doit['nume'] . "/>  </td><td bgcolor='#3399ff'> <b><t><a  class='zzz' href=" . $doit['adresa'] . ">     " . $doit['nume'] . " </a></t></b> <br> <p> Uploaded: " . $data . ", Size: <b>" . $size . " </b> GiB, ULed by: <b> " . $by . " </b> </p>  
        </td>
      </tr>
      </table>";
    
    }
    
    
    Code (markup):
    but in the echo didn't get me the variable from $ebay...
     
    Alice24, Oct 10, 2011 IP
  2. Shamrocks

    Shamrocks Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Will check it out that for you.
     
    Shamrocks, Oct 11, 2011 IP
  3. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thank you. I solved this with LEFT JOIN.
     
    Alice24, Oct 11, 2011 IP