I'm in need of echoing to screen specific records from a table based on the value of one field in the record.
I have a table which has the names and addresses of people
I wish to echo to screen all the records (not all data from the record) where for example the country is "GB".
I have currently tried using a PHP loop through each line record of the table and an if inside to check the value, however this will only echo out the first record in the table which has GB as its' country, and if I change the country to IE it will output nothing, even though there are records with IE set as the country.
$country = "GB";
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('amazondb', $conn);
$result = mysql_query("SELECT ID, PurchaseDate, BuyerName, BuyerPhoneNumber, BuyerEmail,
ShipAddress1, ShipAddress2, ShipAddress3, ShipCountry FROM imported_orders");
while($row = mysql_fetch_array ($result))
{
if ($row['ShipCountry']=="GB")
{
echo "<br><b>Current Order ".$row['ID']."</b><br>";
echo "<b>Date Purchased: </b>".$row['PurchaseDate']."<br>";
echo "<b>Buyer Details</b><br>";
echo "<b>Name : </b>".$row['BuyerName']."<b> Phone Number: </b>".$row['BuyerPhoneNumber']."<b> Email: </b>".$row['BuyerEmail']."<br>";
echo "<b>Delivery Address</b><br>";
echo "<b>Address Line 1 : </b>".$row['ShipAddress1']."<b> Address Line 2: </b>".$row['ShipAddress2']."<b> Address Line 3: </b>".$row['ShipAddress3']."<br>".$row['ShipCountry'];
}
}
I have also tried this with SQL SELECT WHERE:
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('amazondb', $conn);
$result = mysql_query("SELECT * FROM imported_orders WHERE ShipCountry='GB'");
while($row = mysql_fetch_array ($result))
{
echo "<br><b>Current Order ".$row['ID']."</b><br>";
echo "<b>Date Purchased: </b>".$row['PurchaseDate']."<br>";
echo "<b>Buyer Details</b><br>";
echo "<b>Name : </b>".$row['BuyerName']."<b> Phone Number: </b>".$row['BuyerPhoneNumber']."<b> Email: </b>".$row['BuyerEmail']."<br>";
echo "<b>Delivery Address</b><br>";
echo "<b>Address Line 1 : </b>".$row['ShipAddress1']."<b> Address Line 2: </b>".$row['ShipAddress2']."<b> Address Line 3: </b>".$row['ShipAddress3']."<br>".$row['ShipCountry'];
}
I've used this while loop many times and its been fine, however the introduction of the if, and WHERE cause is to just display the first record if the specific value I want is present.
This code is currently being tested in its own file, so there is no other code which could be interfering, what I've posted here is its entirety.
Thanks for any help, its probably something obvious I'm just overlooking.