売れ筋ランキング

$row){ if(isset($_SESSION['sales'])){ if(array_key_exists($row['pid'],$_SESSION['sales'])){ ++$_SESSION['sales'][$row['pid']]; }else{ $_SESSION['sales'] += array($row['pid'] => 1); } }else{ $_SESSION['sales'] = array($row['pid'] => 1); } } if(isset($_SESSION['sales'])){ arsort($_SESSION['sales']); } $sql='select * from product order by pstock'; $result = php_query($sql); if(isset($_SESSION['sales'])){ foreach($result as $record => $row){ if(key(array_slice($_SESSION['sales'], 0, 1, true)) == $row['pid']){ $s_stock = $_SESSION['sales'][$row['pid']]; echo "
"; echo "

1位 ". $row['pname'] . "

"; echo ""; echo ""; echo "

"; echo "
メーカー
" . $row['pmaker'] . "
"; echo "
価格
" . $row['pprice'] . "円
" ; echo "
販売数
" . $s_stock . "個
"; echo "
"; echo "
"; } } $sql='select * from product order by pstock'; $result = php_query($sql); foreach($result as $record => $row){ if(key(array_slice($_SESSION['sales'], 1, 1, true)) == $row['pid']){ $s_stock = $_SESSION['sales'][$row['pid']]; echo "
"; echo "

2位 ". $row['pname'] . "

"; echo ""; echo ""; echo "

"; echo "
メーカー
" . $row['pmaker'] . "
"; echo "
価格
" . $row['pprice'] . "円
" ; echo "
在庫数
" . $s_stock . "個
"; echo "
"; echo "
"; } } $sql='select * from product order by pstock'; $result = php_query($sql); foreach($result as $record => $row){ if(key(array_slice($_SESSION['sales'], 2, 1, true)) == $row['pid']){ $s_stock = $_SESSION['sales'][$row['pid']]; echo "
"; echo "

3位 ". $row['pname'] . "

"; echo ""; echo ""; echo "

"; echo "
メーカー
" . $row['pmaker'] . "
"; echo "
価格
" . $row['pprice'] . "円
" ; echo "
在庫数
" . $s_stock . "個
"; echo "
"; echo "
"; } } echo "" . ""; unset($_SESSION['sales']); } ?>