+ Reply to Thread
Results 1 to 6 of 6

Thread: I need help pls

  1. #1
    mby247 is offline x10Hosting Member mby247 is an unknown quantity at this point
    Join Date
    Jun 2010
    Posts
    2

    I need help pls

    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.

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

    <?php
    //Connect To Database
    $hostname='localhost.com';
    $username='forexample';
    $password='xxxx';
    $dbname='example';
    $usertable='ECMY4572957';

    mysql_connect($hostname,$username, $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($track_number) <= 0 || strlen($track_number) > 15){
    die('<b>Invalid tracking number, please go back</b>');
    }
    else{
    $correct_tracking_numbers=array(ECMY4572957, BHSZ006933);
    if(in_array($track_number,$correct_tracking_number s)){
    $query = 'SELECT * FROM ' . $usertable;
    $result = mysql_query($query) 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_array($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>


    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 "FTYX34555867". 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.

  2. #2
    as4s1n's Avatar
    as4s1n is offline x10 Sophmore as4s1n is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Washington State
    Posts
    174

    Re: I need help pls

    Your question is a bit vague. If you want to call the data from another table as well as keeping the original data table, just create a second $query, call it $query2 or something, and then rewrite the info to get from the database:
    PHP Code:
    $query2 'SELECT * FROM ' $usertable;
    $result2 mysql_query($query2) or die(mysql_error());
    # ...
    while($row=mysql_fetch($result2)) {
    # Rows 
    And you should be good.
    There is no such thing as a "stupid question," there are only "stupid people" who don't ask them.

  3. #3
    varunaroli is offline x10Hosting Member varunaroli is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    4

    Re: I need help pls

    <?php
    //Connect To Database
    $hostname='localhost.com';
    $username='forexample';
    $password='xxxx';
    $dbname='example';
    $usertable='ECMY4572957';

    $usrtble2=' enter second table name '

    mysql_connect($hostname,$username, $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($track_number) <= 0 || strlen($track_number) > 15){
    die('<b>Invalid tracking number, please go back</b>');
    }
    else{
    $correct_tracking_numbers=array(ECMY4572957, BHSZ006933);
    if(in_array($track_number,$correct_tracking_number s)){
    $query = 'SELECT * FROM ' . $usertable;
    $result = mysql_query($query) 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_array($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>";


    // here you can write another sql query to connect your second table.





    }
    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>


    ok all the best.

  4. #4
    callumacrae's Avatar
    callumacrae is offline not alex mac callumacrae is just really nice
    Join Date
    Dec 2007
    Location
    Wellesbourne, England
    Posts
    5,162

    Re: I need help pls

    Whats with all the seperate echos? echo "<br><br><br>"; is much better :D

    And <br> should be written as <br /> to make it XHTML compliant.

    ~Callum
    I can customise your phpBB board. Send me a PM.
    lynxphp - info, tutorials and scripts
    "A forum post should be like a skirt; long enough to cover the subject but short enough to keep things interesting."

  5. #5
    mby247 is offline x10Hosting Member mby247 is an unknown quantity at this point
    Join Date
    Jun 2010
    Posts
    2

    Re: I need help pls

    Dear friend,
    Thanks for the assistance and help. Must greatful and I really appreciate. The main problem am having is.....I got 2 tables in a database...am I correct if I write it this way?

    //Connect To Database
    $hostname='localhost';
    $username='fooexample';
    $password='xxxxxx';
    $dbname='fooexample';
    $usertable='ECMY4572957';
    $usertable2='FTYX34555867';
    $usertable3='FTYS56869456';
    $usertable4='GTVX34554367';

    Also how to I run each table independently...the logic is it is a shipping website and the table are tracking history for each customer. I want them to be able to view the tracking history on the table without them seeing the order table. As you can see below the script if for the first table...so I do I go about with the other tables? Can you please explain.

    mysql_connect($hostname,$username, $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($track_number) <= 0 || strlen($track_number) > 15){
    die('<b>Invalid tracking number, please go back</b>');
    }
    else{
    $correct_tracking_numbers=array(ECMY4572957, BHSZ006933);
    if(in_array($track_number,$correct_tracking_number s)){
    $query = 'SELECT * FROM ' . $usertable;
    $result = mysql_query($query) or die(mysql_error());
    echo "<b>Container Number: ECMY4572957</b>";
    echo "<br>";
    echo "<br>";
    echo "<b>B/L Number: BHSZ006933</b>";
    echo "<br>";
    echo "<br>";
    echo "<b>Estimated Delivery: 14 Days</b>";
    echo "<br>";
    echo "<br>";
    echo "<b>Port of Loading : Port Klang, Malaysia</b>";
    echo "<br>";
    echo "<br>";
    echo "<b>Port of Transshipment : Port Moresby, Papau New Guinea</b>";
    echo "<br>";
    echo "<br>";
    echo "<b>Port of Discharge/Unloading: Port Honiara, Solomon Island</b>";
    echo "<br>";
    echo "<br>";
    echo "<b>NOTE</b>:<i>Container to be transshipped with another Shipping Line in Papau New Guinea. Once container is <br>transshipped, we would advice the delivery carrier and their Agent contact details in Solomon Island.</i></br>";
    echo "<br>";
    echo "<br>";
    echo "<b>SHIPMENT HISTORY</b>";
    echo "<br>";
    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_array($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>

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: I need help pls

    Quote Originally Posted by Alex Mac View Post
    echo "<br><br><br>"; is much better :D
    Better still would be to use lists (<ul> or <dl>, which are semantic, unlike <br/>) and styling for layout.

    mby247:
    When asking about code, please use the [code], [php] or [html] tags (as appropriate) to separate and format code. As it is, it's not very readable. Also, don't throw up all your code; post a minimal test case.

    Don't use SELECT *; explicitly specify the columns you want.

    The old mysql driver is outdated. Consider switching to the newer PDO driver, which is more performant and easier to secure. For a tutorial, read "Writing MySQL Scripts with PHP and PDO".
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to 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
x10hosting free hosting for the masses
dedicated servers