开发者

Why in this php code the indexes ["name"],["price"] and ["id"] won't display any data?

$result= mysql_query("SELECT
   cart.id    cart_id,
   dkb.id     dkb_id,
   cdkb.id    cdkb_id,
   dbl.id     dbl_id,
   cart.*,
   dkb.*,
   cdkb.*,
   dbl.*
FROM
    cart

    LEFT OUTER JOIN dkb
       ON ( cart.id = dkb.id
            AND dkb.id = '".$ids."' )

    LEFT OUTER JOIN dbl
       ON ( dbl.id = dkb.id )

    LEFT OUTER JOIN cdkb
       ON ( cart.id = cdkb.id
            AND cdkb.id = '".$id."' )
WHERE
    cart.cookieId ='" . GetCartId() . "' ' ORDER BY cdkb.name AND dkb.name ASC");

$totalCost=0;
while($row = mysql_fetch_array($result))
{  
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["price"]);?>

<select name="<?php echo $row["id"]; ?>" onChange="UpdateQty(this)">

<?php echo $row["name"]; ?></p></div>

In the above query and php script the $row["id"], $row["name"] and $row["price"] fields from cdkb, dkb and cart tables won't display in the nothing in the html code. Well at least the $row["name"] is not displaying the name of the item does开发者_运维百科 not appear in the database with the query set up above. Does the SELECT clause has to do something with it? maybe there has not been a field assigned in the SELECT clause that might be producing that $row["name"] no to appear.

Last issue...Tuesday, February 16, 2009 PART2

------------EDITED PART2-------------------

$is= isset($_GET['is'])?(int) $_GET['is']:null; $ic= isset($_GET['is'])?(int) $_GET['is']:null;

$result = mysql_query("SELECT cart.id cart_id, dkb.id dkb_id, cdkb.id cdkb_id, dbl.id dbl_id,

FROM cart

LEFT OUTER JOIN dkb
   ON ( cart.id = dkb.id and dkb.id = $is )

LEFT OUTER JOIN cdkb
   on ( cart.id = cdkb.id and cdkb.id = $ic )

WHERE cart.id = 1" );

--Error message below is what Run SQL query/queries on database phpmyadming program is displaying of EDIT PART2--

#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

I have changed the fields as they have been aliases different but still displays the same error #1064 Don't see what's the SQL syntax error here help...


you have multiple columns that call "name"

in your select , add to the list of fields :

cdkb.name as name1 ,dkb.name as name2 ....

and then echo $row['name1'] ...


Using more than one star in SELECT-query - bad practice. You can get conflict with column names and your code can become erroneous.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜