사용자가 장바구니에 추가 한 무관심한 결과를 보여주고 싶습니다.¿ 관련 제품을 장바구니 제품에 표시하는 방법은 무엇입니까?
URL을 클릭하여 GET
방법으로 제품에서 ID
을 얻습니다.
<a href=http:./cart/$id/$url>
내 예를
products
테이블 만 6 기록이, 그 6 개 제품을 구입하는 말을하는 것입니다. 사용자가 지금 내 질문은 id5
id1
id3
으로 구입하기 위해 3 개 제품을 추가 할 경우
이제, 내가 어떻게이 경우, 사용자가 구입하지 않은 테이블 products
에서 다른 제품을 표시 할 수 있습니다 id2
id4
id6
, 전에 언급 한대로 id5
id1
id3
을 구입했습니다.
내가 쇼핑 카트의 무관심 결과에 대해 생성됩니다 쿼리는 다음과 같다 :
$result = $c->prepare("SELECT id_tutorial,page,titulo,info,icon,bg,vdo,url,precio,duracion,status FROM tutoriales WHERE id_tutorial!=? and status=1 LIMIT 6");
미안 논리 !=
또는 <>
하지만이 과정을 알고하지는 지출 이 쿼리 결과로 작업하기 전에 수행해야합니다.
<?php //Shopping Cart (./cart.php)
//GET -> id of the product.
if (isset($_GET['articulo'])) {
$id_tutorial = $_GET['articulo'] ?: '';
//If the session is defined for Shop Cart.
if (isset($_SESSION['carrito'])) {
//Get data from session.
$arreglo = $_SESSION['carrito'];
$encontro = false;
for ($i=0; $i<count($arreglo); $i++) {
//checking if product has already been added to the cart.
if ($arreglo[$i]['Id'] == $_GET['articulo']) {
$encontro = true;
}
}
//If find product is false, update de array session (Shop cart).
if ($encontro == false) {
//Reset
$titulo = "";
$precio = 0;
$icon = "";
//Get data from DB.
$stmt = $c->prepare("SELECT titulo,precio,icon FROM tutoriales WHERE page=? and status=1");
$stmt->bind_param("i",$_GET['articulo']);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($titulo,$precio,$icon);
while ($stmt->fetch()) {
//New data for array.
$datosnuevos = ['Id' => $_GET['articulo'], 'Titulo' => $titulo, 'Precio' => $precio, 'Icon' => $icon, 'Cantidad' => 1 ];
//array_push($arreglo, $datosnuevos);
$arreglo[] = $datosnuevos;
$_SESSION['carrito'] = $arreglo;
//Count total of products added to the cart.
$data = $_SESSION['carrito'];
$value_carrito = count($data);
$_SESSION['compras'] = $value_carrito;
} $stmt->close();
} else {
$stmt->close();
}
}
} else { //If session is not defined for Shop Cart, that is to say that the card is in 0 productos.
//Reset.
$titulo = "";
$precio = 0;
$icon = "";
//Get data from DB.
$stmt = $c->prepare("SELECT titulo,precio,icon FROM tutoriales WHERE page=? and status=1");
$stmt->bind_param("i",$_GET['articulo']);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($titulo,$precio,$icon);
while ($stmt->fetch()) {
//Started the array for Shop Cart.
$arreglo[] = ['Id' => $_GET['articulo'], 'Titulo' => $titulo, 'Precio' => $precio, 'Icon' => $icon, 'Cantidad' => 1 ];
$_SESSION['carrito'] = $arreglo;
//Count total of products added to the cart.
$data = $_SESSION['carrito'];
$value_carrito = count($data);
$_SESSION['compras'] = $value_carrito;
} $stmt->close();
} else {
$stmt->close();
}
}
}
?>
'$ arreglo [] = [ 'Id'=> $ _GET [ 'articulo'], ... 'while()'루프의 각 반복에서 동일한 제품 ID를 얻고 있습니다. ? –
예,이 행의 제품 ID는 [ 'Id'=> $ _GET [ 'articulo']입니다. –
아래 답변을 주셨습니다. 바라기를 이것은 당신의 문제를 해결할 것입니다. –