The error is coming from this line 21
LEFT OUTER JOIN dkb
ON ( cart.id = dkb.id and dkb.id = $is ) line 21
Error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM cart LEFT OUTER JOIN dkb ON (cart.id = dkb.i' at line 21
The error below is being generated by the Run SQL query/queries.
$is= isset($_GET['is'])?(int) $_GET['is']:null;
$ic= isset($_GET['is'])?(int) $_GET['is']:null;
$result = mysql_query("SELECT
cart.id AS cart_id,
cart.qty AS qty,
dkb.id As dkb_id,
dkb.price AS price1,
dkb.name As name1,
cdkb.id As cdkb_id,
cdkb.price AS price2,
dkb.name As name2,
dbl.id As dbl_id
FROM
cart
LEFT OUTER JOIN dkb
ON ( cart.id = dkb.id and dkb.id = $is )
LEFT OUTER JOIN dbl
ON ( dbl.id = dkb.id )
LEFT OUTER JOIN cdkb
on ( cart.id = cdkb.id and cdkb.id = $ic )
WHERE cart.id = '" . GetCartId() . "'ORDER BY dkb.name AND cdkb.name ASC" );
<?php
$totalCost=0;
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["price1"]);?>
<select name="<?php echo $row["dkb_id"]; ?>" onChange="UpdateQty(this)">
<?php echo $row["name1"]; ?></p></div>
Maybe $is or $ic is null. You should cast the null to 0 or something else because your code will break otherwise. Also, it isn’t a crime to use descriptive variable names. I bet $500 you won’t have a clue what $is or $ic means in 1 month.
Odd enough now the RUN query/queries in database x is not displaying any type of error or notice when I run the query. Well but it still won’t display the data or values of the fields. Well taking into consideration to what alianDev said that
$is= isset($_GET['is'])?(int) $_GET['is']:null;
If $is is set { (int) $_GET[‘is’]} else null.
Well we have $is and $ic one and one variable is coming from one page1.php and another page2.php therefore one of the set above will end up null because is either one of them that will have a value since user can not access to pages at once. I understand that. So at the query one of the LEFT OUTER JOINS will come as null throwing out the query? Well what I understand about LEFT OUTER JOINS is that one or the other are going to be set depending which variable will isset $is or $ic well I might be lost in this last part. But the over all desired effect intended is that the first LEFT OUTER JOIN display its fields value together with the second LEFT OUTER JOIN which is dbl and the third LEFT OUTER JOIN to come null or get unable to display it’s field values when the first and second LEFT OUTER JOIN are active, that’s the purpose. Right now I believe that’s what the query set up is to generate. Now The Null value of either $is or $ic might be throwing off the query I don’t know.
What’s your opinion.
Help.
@r937 It won’t produce the same error now it will display Showing rows 0 - 3 (4 total, Query took 0.0116 sec) I believe It means its ok.
@AlienDev the result of the query at the phpmyadming is that the three fields below will contain it’s data but then the rest name, price, etc will come up as NULL and those the fields that depends on the results and values of $ic and $is.
cart.id AS cart_id,
cart.qty AS qty,
dkb.id As dkb_id,
SELECT
cart.id AS cart_id,
cart.qty AS qty,
dkb.id As dkb_id,
dkb.price AS price1,
dkb.name As name1,
cdkb.id As cdkb_id,
cdkb.price AS price2,
dkb.name As name2,
dbl.id As dbl_id
FROM
cart
LEFT OUTER JOIN dkb
ON ( cart.id = dkb.id and dkb.id = '' )
LEFT OUTER JOIN dbl
ON ( dbl.id = dkb.id )
LEFT OUTER JOIN cdkb
on ( cart.id = cdkb.id and cdkb.id = '')
WHERE cart.id = 'ec16801d4a33e4bcc3a463d3a056ef66'ORDER BY dkb.name AND cdkb.name ASC
Can’t believe that both are resulting NULL ‘’ empty when actually coming from page1.php and page2.php
That means that the code below is not passing anything and in the URL display the [‘is’] field has a value value.
Look at the is variable at the url it has a value of two and in the echo of the query is displaying as empty what should be wrong that is showing it as not being set.
That’s what empty means, It is an integer the url has a value so or it is getting lost in between the url and the $_GET[‘ids’]. I have added the function intval in
LEFT OUTER JOIN dkb
ON ( cart.id = dkb.id
and dkb.id =‘“.intval( $is).”’
And not the query echo return as instead of
dkb.id = ‘’ )
it will return
dkb.id = ‘0’)
It’s the same empty value.
LEFT OUTER JOIN dkb
ON ( cart.id = dkb.id
and dkb.id = $is)
And if I get the quotes around $is and $ic variables then it will come up as NULL it will return
dkb.id = ) and with a warning such as
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /store/public_html/cart.php on line 308
if only one of two variables is going to be present, what is keeping you from ~not~ including in the query the LEFT OUTER JOIN for the table which has the column that’s supposed to match the variable that’s missing?
SELECT
cart.id AS cart_id,
cart.qty AS qty,
dkb.id As dkb_id,
dkb.price AS price1,
dkb.name As name1,
cdkb.id As cdkb_id,
cdkb.price AS price2,
dkb.name As name2,
dbl.id As dbl_id
FROM
cart
LEFT OUTER JOIN dkb
ON cart.id = dkb.id
LEFT OUTER JOIN dbl
ON dbl.id = dkb.id
LEFT OUTER JOIN cdkb
ON cart.id = cdkb.id
WHERE cart.id = 'ec16801d4a33e4bcc3a463d3a056ef66'ORDER BY dkb.name AND cdkb.name ASC
I took the two conditions after the AND clause on dkb and cdkb tables and now it’s displaying. I thought that I need those two conditions in order to get the results I am having with the above query!
So the variables are not needed any more. There was a point where there was a value in the variable in the former query but still it was not displaying any result so I think so how the last query set up was not for this case.