0

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'");



}

?>
3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by Mirth
0

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.

0

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. :(

0

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.

0

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'");
0

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 :)

Edited by vaultdweller123: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.