My code is trying to assign a truck per location. My problem is in the Truck column, only one truck value is assigned for all, but when I use echo to see if my if-else works, it does. In fact, the correct truck is assigned for each location. But in the database, only 1 type of truck (e.g. truck1) is assigned for all. Please help. Thanks is advance!

<?php
include ("database_connection.php");
connect();

$i = 0;
$result1 = mysql_query("SELECT * FROM `customer_information` ci join `customer_order` co WHERE ci.Customer_Number= co.Customer_Number AND co.Customer_Number = co.Customer_Number");
$count = mysql_num_rows($result1);
if ($count != 0)
	while($row1 = mysql_fetch_array($result1)){
		$i++;
		$order_no = $row1['Order_Number'];
		$cust_no = $row1['Customer_Number'];
		$receipt_no = $row1['Receipt_Number'];
		$date_ordered = $row1['Date_Ordered'];
		$exp_date = $row1['Expected_Date'];
		$location = $row1['Location'];
		
		
    
	if ($location == 'place1' || $location == 'place2' || $location == 'place3')
	{
		$truck = "truck1";
		
	} else if ($location == 'place4' || $location == 'place5' || $location == 'Caloocan' || $location == 'place7')
		{
			$truck = "truck2";
		}	else if ($location == 'place8' || $location == 'place9')
			{
				$truck = "truck3";
			
			}	

mysql_query("UPDATE customer_order set `Truck` = '$truck' where Location = '$location'");



}

?>

Recommended Answers

All 8 Replies

Member Avatar for rajarajan2017

Method I:

SELECT * FROM `customer_information` ci join `customer_order` co WHERE ci.Customer_Number= co.Customer_Number AND co.Customer_Number = co.Customer_Number

Check the above query in your phpmyadmin sql editor and check the location column whether it has data other than "place1" "place2" & "place3". If not, then query is running properly and coming output is right. (ie. you should change your query to your needs)

Method II:

$location = $row1['Location'];
echo $location;

echo the location to know what it is returned.

I tried the echo. It returns the right value.But it does not store the right value inside the database. It only stores 1 truck value for all. :(

Member Avatar for rajarajan2017

That is not possible, you mistakenly doing something. If it returns place4 then why its not entering within the if statment. May be use trim($location) to avoid spaces between left and right. Then check it.

hi mirth... filipinio ka noh? kac nakita ko yung location = caloocan. hahaha tol try mo daw change to

mysql_query("UPDATE customer_order set `Truck` = '$truck' where Location = '$location'");

to

mysql_query("UPDATE customer_order set `Truck` = '$truck' where Location = '$cust_no'");

Haha yup! Salamat. Pero ayaw pa din e. Banas.

Member Avatar for rajarajan2017

Please post the word in the language everybody knows, may be used in brackets.

aw mali hahaha

mysql_query("UPDATE customer_order set `Truck` = '$truck' where Customer_Number = '$cust_no'");

paki change yung Location to Customer_Number sa where clause mo ^_^, btw dapat mag english na tau baka magalit ang admin sakin :)

Ok. It worked! Thanks :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.