Q. about joining two tables in SQL?? pl.

  • 13 years ago

     

    Hi everybody

     

    I need help from you on my assingnment

     I  have two tables created in database by  http://localhost/phpmyadmin/

    then I put some information in these tables and they have two feilds the same in each

    I want to join these two tables by (PHP coder software)

    but I tried many ways of methods and no result

    this is my code I put .... can anyone tell what's wrong with it  .. help me  *_^

    Hint: i want all the information of each student from the two tables appear in the localhost

     --------------------------------------------------------------------------------------------------------------------------------

    <?php
    $host = "localhost";
    $user = "";
    $password = "";

    $db = "test";

    $sql= "SELECT student.STD_NAME, hostel.HST_LOCATION
          FROM student
          LEFT JOIN hostel
          ON student.STD_ROOM=hostel.HST_ROOM ";
         
         
    mysql_connect ($host,$user,$password) or die("Failed to connect");
    mysql_select_db($db) or die("Failed to select $db");

    $result = mysql_query($sql) or die("Could Not excute query $sql");
    $row = @mysql_fetch_array($result);

    echo " ".$row["STD_NAME"]." ".$row["HST_LOCATION"]." ";
    ?>

    -----------------------------------------------------------------------------------------------------------------------------

     

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou