www.webdeveloper.com
Results 1 to 6 of 6

Thread: How to receive info from 2 tables from the same database in the same page?

  1. #1
    Join Date
    Oct 2013
    Posts
    28

    How to receive info from 2 tables from the same database in the same page?

    I have 1 big form that will receive information from 2 different tables (table1 and table2) in the same database.

    All info will be placed in the same form where you can save it all to a new table.

    My issue is when some of the row in both table (table1 and table2) have the same name how do I call the info from the correct table. So fare I have:

    1.
    The URL that will call the info looks like:

    PHP Code:
    .info.php?id=320&folder=ras 

    2.
    The query:

    PHP Code:
    if(!$_POST["submit"])
    {
    //INFO FORM TABLE 1
    $query mysql_query("select country, state, name, dob from table1 where id = '".$_GET["id"]."' ");
    $row mysql_fetch_row($query);
    $country $row[0];
    $state $row[1];
    $name $row[2];
    $dob $row[3];

    //INFO FORM TABLE 2
    $query mysql_query("select country, state, name, dob from table2 where folder = '".$_GET["folder"]."' ");
    $row mysql_fetch_row($query);
    $country $row[0];
    $state $row[1];
    $name $row[2];
    $dob $row[3]; 
    3.
    The vaiable on the website:
    PHP Code:
    From table 1: //1 <?=$country?> //2 <?=$state?> //3 <?=$name?> //4 <?=$dob?> 
    From table 2: //1 <?=$country?> //2 <?=$state?> //3 <?=$name?> //4 <?=$dob?>

    Im not sure how to do this, but I think that I need to change one of the query to something like:
    PHP Code:
    $query2 mysql_query("select country, state, name, dob from table2 where folder = '".$_GET["folder"]."' ");
    $row mysql_fetch_row($query2);
    $country $row[0];
    $state $row[1];
    $name $row[2];
    $dob $row[3]; 

    But if I do that what variable should I use to call the info in table2?
    PHP Code:
    <?=$2”country”?>
    don’t work.

    Please advice.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    Why not prefix each of your retrieved $row vars with a letter

    $icountry = $row[0];
    $istate = $row[1];

    and
    $fcountry = $row[0];
    $fstate = $row[1];

    Then in your html just use the (now) unique names.

  3. #3
    Join Date
    Oct 2013
    Posts
    28
    Thanks for the reply. Dues you mean like:
    $query = mysql_query("select country, state, name, dob from table2 where folder = '".$_GET["folder"]."' ");
    $row = mysql_fetch_row($query);
    $gcountry = $row[0];
    $gstate = $row[1];
    $gname = $row[2];
    $gdob = $row[3];
    Is the above correct? Or do I need to change anything else?

    Can you show a compleat example of:
    Then in your html just use the (now) unique names.
    THANKS

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    I think I gave you enough to get the idea....

  5. #5
    Join Date
    Oct 2013
    Posts
    28
    To help others that dont understand what (now) Means I will show here how the codes should look like:
    <?=$gcountry?>
    this will call the info from table 2!

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    851
    Forget the word now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles