I need help pls

mby247

New Member
Messages
2
Reaction score
0
Points
0
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>';
}
}
?>
</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.
 

as4s1n

New Member
Messages
174
Reaction score
4
Points
0
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:
$query2 = 'SELECT * FROM ' . $usertable;
$result2 = mysql_query($query2) or die(mysql_error());
# ...
while($row=mysql_fetch($result2)) {
# Rows
And you should be good.
 

varunaroli

New Member
Messages
4
Reaction score
0
Points
0
<?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_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>";


// 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.
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
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
 

mby247

New Member
Messages
2
Reaction score
0
Points
0
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>
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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 [URL="http://stackoverflow.com/questions/321299/what-is-the-reason-not-to-use-select"]SELECT *[/URL]; explicitly specify the columns you want.

The old mysql driver is outdated. Consider switching to the newer [URL="http://php.net/PDO"]PDO[/URL]  driver, which is more performant and easier to secure. For a tutorial, read "[URL="http://www.kitebird.com/articles/php-pdo.html"]Writing MySQL Scripts with PHP and PDO[/URL]".
 
Top