How to connect two tables on php file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mby247
    New Member
    • Jun 2010
    • 1

    How to connect two tables on php file.

    Pls I need help. I got two tables on a database but I dont know how to run them independently. Please find below our script. It is a shipping tracking website. All I want is each table to run independently once tracked.

    [code=php]<?php
    //Connect To Database
    $hostname='loca lhost.com';
    $username='fore xample';
    $password='xxxx ';
    $dbname='exampl e';
    $usertable='ECM Y4572957';

    mysql_connect($ hostname,$usern ame, $password) OR DIE ('Unable to connect to database! Please try again later.');
    mysql_select_db ($dbname);

    //This array contains all correct tracking numbers
    $track_number = $_POST['track_number'];
    if(empty($track _number)){
    die('<b>Please go back & enter tracking number</b>');
    }
    else if(strlen($trac k_number) <= 0 || strlen($track_n umber) > 15){
    die('<b>Invalid tracking number, please go back</b>');
    }
    else{
    $correct_tracki ng_numbers=arra y(ECMY4572957, BHSZ006933);
    if(in_array($tr ack_number,$cor rect_tracking_n umbers)){
    $query = 'SELECT * FROM ' . $usertable;
    $result = mysql_query($qu ery) or die(mysql_error ());
    echo "<table border='5'>
    <tr>
    <th>Date/Time</th>
    <th>Event</th>
    <th>Location</th>
    <th>Details</th>
    <th>Type of Move</th>
    </tr>";
    while($row = mysql_fetch_arr ay($result)){
    echo "<tr>";
    echo "<td>" . $row['Date/Time'] . "</td>";
    echo "<td>" . $row['Event'] . "</td>";
    echo "<td>" . $row['Location'] . "</td>";
    echo "<td>" . $row['Details'] . "</td>";
    echo "<td>" . $row['Type of Move'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";
    echo "<br>";

    }else{
    echo '<b>The tracking number is invalid, Please go back & enter a Valid Tracking Number!</b>';
    }
    }
    ?>
    </body>
    </html>[/code]

    How do I write or connect the second usertable to the php file as the first script which is working fine once tracked? The table name is "FTYX345558 67". I don't know how to run or write multiple table on same database. All I need is, how to connect multiplt tables so each table can run different tracking number. Am stress as am not getting it well. Please help me.
    Last edited by Atli; Jun 6 '10, 06:10 AM. Reason: Please use [code] tags when posting code snippets.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    What does the second table contain? same thing as the first?

    Do you need to check each tracking number against both tables?

    It's not clear "what" you want to do with the second table. You can't "run" tables. tables is just a collection of data. so what is this data and what do you want to do with it?


    Dan

    Comment

    Working...