2017-02-07 1 views
0

과제에 대한 웹샵을 만들려고하고 있는데 내 체크 아웃에 같은 제품 2 개가 표시되는 것을 알아낼 수 없습니다. artikelnr 필드를 기준으로 1 조 .. 2 배 2 조 ... 5 배 등내 PHP 배열의 두 기사

<?php 
session_start(); 

//read out session with article numbers 
$array = $_SESSION['mandje']; 
echo '<center>'; 
echo '<h1> Uw mandje: </h1>'; 
echo '<table style="border: 2px solid black">'; 

//array that checks if there are two of the same article numbers 
$mandje = array(); 

//read out array 
foreach ($array as $artikel) 
{ 
    echo '</br>'; 
    echo $artikel; 
    if (in_array($artikel, $mandje)){ 
     //I need to display the article that i have multiple times here i guess 
    } else { 
     //getting the articles out of the database 
     require ('config.php'); 
     $query = "SELECT * FROM mphp6_meubels WHERE artikelnr = $artikel"; 
     $results = mysqli_query($mysqli, $query); 
     while($meubel = mysqli_fetch_array($results)){ 
      $video = $meubel['naam']; 
      $nmr = $meubel['artikelnr']; 
      echo '<tr>'; 
      echo '<td> <img src="Meubels/'.$video.'.jpg" width="150" height="150" alt="Meubel"></td>'; 
      echo '</tr>'; 
     } 
    } 
    //adding the article to array so i can check if there are multiple of the same articles in array 
    $mandje[] = $artikel; 
} 
echo '</table>'; 
echo '</center>'; 

답변

0

그냥 그룹 : 이것은 내가 좋아하는 뭔가를 표시 할 내 코드입니다.

foreach ($array as $artikel) 
{ 
    require ('config.php'); 
    $query = "SELECT mphp6_meubels.*, count(*) as cnt FROM mphp6_meubels WHERE artikelnr = $artikel GROUP BY artikelnr"; 
    $results = mysqli_query($mysqli, $query); 
    while($meubel = mysqli_fetch_array($results)){ 
     $video = $meubel['naam']; 
     $nmr = $meubel['artikelnr']; 
     echo '<tr>'; 
     echo '<td>' . $artikel . '</td>'; 
     echo '<td> <img src="Meubels/'.$video.'.jpg" width="150" height="150" alt="Meubel"></td>'; 
     echo '<td> ' . $meubel['cnt'] . '</td>'; 
     echo '</tr>'; 
    } 
}