カート内の各アイテムが表示されず、正しい数のアイテムが表示されますが、毎回カートに追加された最初のアイテムが繰り返されるという点で、セットアップしたショッピング カートに問題があります。
何が問題なのかわかりましたが、それを修正する方法がわかりません...基本的に現在、レコードセットに対して1つのクエリのみを実行しており、それが表示されています。私のPHPの基本的な知識では、カート内の各アイテムに対してクエリを実行する必要があると言えます(最大6つしかないため、大きくなることはありません)。
カート内の数字は、データベースの ship_id 番号と同じです.... したがって、次のようなものを入れることができると考えていました:
$sql = "SELECT $ship_id, $ship_name, image
FROM $ship_infomation
WHERE $ship_id = $cartId;";
... foreach ループの内部ですが、これにより問題が発生します
私の小さな問題を解決するために私を導くための最良の方向を誰かが指摘できますか.
どうもありがとう
ショッピングカートの表示:
<?php
$cart = $_SESSION['cart'];
if (!$cart) {echo "<div class='dialogue_box_inside_info_request'>
<div class='dialogue_box_image'>
<img src='images/basket_empty_dialogue.png' width='618' height='264' />
</div>
</div>";}
else
{
$array = explode(',', $_SESSION['cart']);
echo "<table width='835' border = '0'>";
foreach($array as $cartId) {
$ship_name = $row_ships['ship_name'];
$ship_image = $row_ships['image'];
echo "<tr>";
echo "<td width='110' height='58' class='table_text'><img src='images/ships/$ship_image'width='83' height='53' /> </td>";
echo "<td width='620' height='58' class='table_text'>$ship_name</td>";
echo "<td width='35' height='58' class='table_text'><a href='cart.php?action=delete&ship_id=$cartId'><img src='images/trash.png' width='31' height='42' /></a></td>";
echo "<td height='58'>$cartId</td>";
echo "</tr>";
}
echo "</table>";
}
?>
コードの先頭に配置されたレコードセット
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_ships, $ships);
$query_ships = "SELECT ship_id, ship_name, image FROM ship_infomation";
$ships = mysql_query($query_ships, $ships) or die(mysql_error());
$row_ships = mysql_fetch_assoc($ships);
$totalRows_ships = mysql_num_rows($ships);
?>