What is wrong with my mySQL query? Left Join/Inner Join
Basically this script exports all of the orders in our little system to a CSV file. There are 4 separate tables that are joined to complete this. SEorder, SEtracking, SE_user, users_orders.
Here is the error:
<div id="Error">An error occurred in script '/home/sites/mywebsite.com/web/administration/allorders.php' on line 81:
<br />Undefined index: UserLast
Here is my database query:
//Make the query-select all orders
$query2 ="SELECT DISTINCT o.OrderID, Basket, Title, FirstName, LastName, Suffix, Company, Address1, Address2, City, State, Zip, GiftCard, GiftCardMsg, t.Tracking, u.UserFirst, u.UserLast AS doo ".
"FROM SEorder o ".
"LEFT JOIN SEtracking t ON (o.OrderID = t.OrderID) ".
"INNER JOIN users_orders uo ON (uo.OrderID = o.OrderID) ".
"INNER JOIN SEuser u ON (u.UserID = uo.UserID) ".
"AND Submitted='Y' ".
"ORDER BY OrderDate ASC";
and here is my php to grab the data. this is line 81 that is throwing the error:
$username = $row['UserFirst'] . " " . $row['UserLast'];
I am positive that the table S开发者_运维百科Euser exists, has the column UserLast, and that column has data in it. I am not completely versed on JOIN's though so am I missing something here? I did not create this script, just troubleshooting. Thanks!
It looks like you aliased the UserLast
column as doo
.
because you have queried the UserLast
as doo
so use the doo
index not UserLast
u.UserLast AS doo
Your PHP should say $row['doo']
精彩评论