SQL sözdizimi hata mesajı ile ilgili yardım

3 Cevap php

switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["idc"], $_GET["qty"]);
ShowCart();
break;
}
case "update_item":
{
UpdateItem($_GET["idc"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["idc"], $_GET["id"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
function AddItem($itemId, $qty){


$result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");

$row = mysql_fetch_row($result);
$numRows = $row[0];

if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query

mysql_query("INSERT INTO cart(cookieId, id, qty) values('" . GetCartId() . "', $itemId, $qty)");
//printf ("Inserted records: %d\n", mysql_affected_rows());

}
else
{
// This item already exists in the users cart,
// we will update it instead
 mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");

}

}

function UpdateItem($itemId, $qty)
{

mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
//printf ("Updated records: %d\n", mysql_affected_rows());

}

function RemoveItem($itemId) 
{

mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
}

?>

<?php 
function ShowCart()

{
    $result = mysql_query("SELECT
                  cart.id         cart_id,
                  cart.id         cart_id,
                  cart.cartId     cartId,
                  cart.cookieId   cookie_Id,
                  cart.qty        qt_y,                     
                  cdkb.id         cdkb_id,
                  cdkb.name       name,
                  cdkb.image      image,
                  cdkb.price      price,
                  dkb.id          dkb_id,
                  dkb.name        name1, 
                  dkb.image       image1,
                  dkb.price       price2,
                  dbl.product_id  product_id,
              dbl.price       price3,
              dbl.variety     variety,
              dbl.description description                  
FROM
        cart


        LEFT OUTER JOIN cdkb
           ON cart.id = cdkb.id    

        LEFT OUTER JOIN dkb
           ON cart.id = dkb.id

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


    WHERE
        cart.cookieId ='" . GetCartId() . "' ' ORDER BY cdkb.name AND dkb.name ASC");

    <div id="cart">
<div id="group">
<div id="quantity">Qty</div>
<div id="cartpic">Pic</div>
<div id="product">Product</div>
<div id="cartprice">Price</div>
<div id="remove">Remove</div>
</div>
<?php

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

?>

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

for($i = 1; $i <= 30; $i++)
{
echo "<option ";
if($row["qt_y"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</div>
<div id="cart2">
<img src="images/logopic.gif"<?php /*?><?php echo $row["image1"]; ?><?php */?> alt="we" width="60" height="50" />
</div>
<div id="cart3"><p><?php echo $row["dishname1"]; ?></p></div>



<div id="cart4"><p>
$<?php echo number_format($row["price3"], 2, ".", ","); ?></p></div>

<div id="cart5">
<p><?php
printf('<a href="cart.php?action=remove_item&id=%d&idc=%d&register=%s">Remove</a>', $_GET['id'], $row['ckb_id'], $_GET['register']);
?></p></div>

<hr size="1" color="red" >

<script language="JavaScript">

function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;

document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}

</script>





<?php
}
?>

<font face="verdana" size="2" color="black" style="clear:right;">
<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b></font></td>


<?php
}
?>

Yukarıdaki cart.php güncellenmiş kod ve sorgu. Eğer sorgu altında fark ederseniz, bir süre döngü vardır. Şu anda ise döngü mükemmel dkb tablo için sayfa1.php gelen ürün olan kurulur. Bu döngü bu, kaydetmek tekrar ekran ve yönetmek ecah madde Adet Adet, resim, isim, fiyat ve seçenekleri kaldırın, bunları görüntüleyebilir ve onlara kullanıcının seçtiği gibi birçok ürün tekrar edecek bir şekilde ayarlanır. Peki kurmak alanları ve tasarım arabası görüntülenen bilgiler tablolar DKB ve dbl yukarı çekin alır sayfa2.php gelen kalemlerinden oldukça işe değil. Sorun şu anda Sepete sayfa2.php gelirken şöyle dbl tabloda tasarım, çünkü aynı madde adı üç kez tekrarlar olmasıdır.

INSERT INTO `dbl` (`id`, `price`, `variety`, `description`) VALUES
(1, 20.30, 'Small Tray', 'Serves 6 to 8 people' ),
(1, 25.90, 'Medium Tray', 'Serves 12 to 15 people'),
(1, 30.90, 'Large Tray', 'Serves 18 to 21 people'),
(136, 0.00, 'Small Tray', '', 'small'),
(136, 0.00, 'Medium Tray', '' ),
(136, 0.00, 'Large Tray', ''),
(2, 0.00, 'Small Tray', ''),
(2, 0.00, 'Medium Tray', ''),
(2, 0.00, 'Large Tray', '');

$result = mysql_query("SELECT * FROM .... LEFT OUTER JOIN .... WHERE") // This is the query we have discussed in this forum.
 while($row = mysql_fetch_array($result))
{  if($row['cdkb_id']){
echo "<div>qty</div>";
echo"<div>". $row['image'] . "</div>";
echo"<div>". $row['name'] . "</div>";
echo"<div>". $row['price'] . "</div>";
echo"<div>remove</div>";
}
else{
echo "<div>qty</div>";
echo"<div>". $row['image1'] . "</div>";
echo"<div>". $row['name1'] . "</div>";
foreach ($row['dkb_id'] as $variety) {
echo"<div>".$variety['variety']. $variety['price3'] . "</div>";
// the vriety and price3 field will display three times as in table dbl has three prices and three variety. It is correct to use a foreach loop for  in this case?}
echo"<div>remove</div>"; 
// end of foreach loop inside the else statement
}// end of if else statement
}// end of while loop
?>

Yani son görüntü ve arama için illüstrasyon ve bir nihai ürün olarak mevcut Yani istenen bakalım, aşağıdaki gibidir.

 while($row = mysql_fetch_array($result))
{  
if (table cdkb) { 
  [1]qyt         image      name          price        remove
     1            ---       marina        $18.90        remove?    
     }end of if statement
Else table dkb {
   1]qyt            Image         Name             Price                  Remove
     1               ---         marina         Small Tray  $18.90        remove? 
                                                Medium Tray $30.24
                                                Large Tray  $35.90
                  } // end of else statement

                  }//end of while loop

Bana bu konuda nihai elini ver.

3 Cevap

SELECT son alanının sonunda bir virgül vardır. Bunu virgül kaldırmanız gerekir.

SELECT
cart.id    cart_id,
dkb.id     dkb_id,
cdkb.id    cdkb_id,
dbl.id     dbl_id, <-- comma here isn't needed

Bu sonra çok fazla bir virgül var gibi geliyor bana:

dbl.id dbl_id

Edit: sorguda başka hata tablodan bir alanı referans olmasıdır dbl:

dbl.id dbl_id

ama sen çok dbl.id bilinmeyen bir varlıktır Sorguya tablo katılmadan değildir.

$ _GET ['Olduğu'] eğer sorgu da havaya uçurmak olacaktır ayarlanmamış. Sen dize "boş" değil, $ null değer atama ve $ ic ediyoruz. Dize bağlamda null değer boş bir dize (''), yani ON ( cart.id = dkb.id and dkb.id = ) hangi bir sözdizimi hatası ile bitireceğiz.

Böyle bir şey ilk atamasını değiştirmek gerekir:

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