I need help pls

They have: 3 posts

Joined: Jun 2010

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_numbers)){
   
$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>';
}
}
?>

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.

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

To answer your question, connecting to multiple tables is no big deal. You specify the table in every query that is sent.

For example, you define $usertable to be "ECMY4572957", so your query is essentially "SELECT * FROM ECMY4572957".

So, if you want to query "FTYX34555867" instead, you can change the query to something like "SELECT * FROM FTYX34555867". In addition, I would recommend not using the $usertable variable and just put the table name in the query.

I'm not quote following the logic in what you are trying to do in the above code. Can you please explain further? Are you trying to show data from both tables in a seamless list, or are you trying to have two separate lists of data?

They have: 3 posts

Joined: Jun 2010

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_numbers)){
$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>

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

So...each user has their own table?

They have: 3 posts

Joined: Jun 2010

Yes....can u pls help me look into it and help me write a script so I can study n understand beta. Wd be highly g8tful.

He has: 53 posts

Joined: Jun 2010

Hi,

As we know that for retrieving some information from database we use SELECT Query,
Means

(1) SELECT */Column_name FROM Table_name1/name2,
(2) SELECT */Column_name FROM Table_name1/name2 where condition.
Question: I got two tables on a database but I dont know how to run them independently
and I'll send the Registration Form code to you that help you,\

registration_dir.php

<?php
if(isset($_POST['posted'])=='true')
{
$connect=mysql_connect('localhost','root','');
$db=mysql_select_db('dir_db',$connect);

$name=$_POST['dir_name'];
$title=$_POST['dir_title'];
$company=$_POST['dir_company'];
$email=$_POST['dir_email'];
$phone=$_POST['dir_phone'];
$address=$_POST['dir_address'];
$website=$_POST['dir_website'];
$notes=$_POST['dir_notes'];
$search_conent=$_POST['dir_search_content'];
           
// Now, We Perform Saving Operation.
               
if(isset($_POST['dir_save']) == 'Save')
                  {
                   
$query=mysql_query("INSERT INTO dir_registration(name,title,company,email,phone,address,website,notes)                           VALUES('$name','$title','$company','$email','$phone','$address','$website','$notes')",$connect);
                  }
                 
//Now We Perform Cancel operation.
              
if(isset($_POST['dir_cancel']) == 'Cancel')
                {
                    exit();
                }
// Now We Perform Reset operation.
               
if(isset($_POST['dir_reset']) == 'Reset')
                {
                   
$name       = '' ;
                   
$title      = '' ;
                   
$company    = '' ;
                   
$email      = '' ;
                   
$phone      = '' ;
                   
$address    = '' ;
                   
$website    = '' ;
                   
$notes      = '' ;
                    echo
'Sai Ram, Sucessfully record Reset';
                }
// Now We Perform Search Operation.       
              
               
if(isset($_POST['dir_search'])=='Search')
                {
                   
$query=mysql_query("SELECT * FROM dir_registration WHERE name LIKE '%$search_conent%'",$connect);
                    while(
$row = mysql_fetch_array($query))
                    {
                       
$column1=$row['name'];
                       
$column2=$row['title'];
                       
$column3=$row['company'];
                       
$column4=$row['email'];
                       
$column5=$row['phone'];
                       
$column6=$row['address'];
                       
$column7=$row['website'];
                       
$column8=$row['notes'];
                    }
                   
                }
//Now We Perform Deletion Operation
               
               
if(isset($_POST['dir_delete']) == 'Delete')
                {
                    echo
"Hiii";
                   
$query = mysql_query("DELETE FROM dir_registration WHERE name= '$name' ",$connect);
                }
}
?>

 
 
 
 

Name :

Title :   
Company :

Email

Phone

Address

<?php
echo $column6;
?>

Website

Birthday
 

Notes

<?php
echo $column8;
?>

They have: 4 posts

Joined: Jul 2010

I think its for the basic table... But i got confusion...

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.