-2
현재 세션을 사용하여 코드를 업그레이드하는 데 어려움을 겪고 있습니다. 이 사건은 웹 카트에 관한 것입니다. 이제 장바구니 프로세스에 추가됩니다. 세션을 사용하여 사용자가 선택한 항목을 유지하려고합니다. 하지만이 세션을 사용할 때마다이 작업이 발생하지 않는 것으로 보입니다. 이 문제를 도와주세요. btw, 이것이 코드입니다.다차원 배열에서 세션이 작동하지 않습니다.
<?php session_start();
$q1=isset($_REQUEST['attack']) ? $_REQUEST['attack'] : 'no_value';
if(is_numeric($q1)){ $q1=number_format($q1,0);}
$q2=isset($_REQUEST['binge']) ? $_REQUEST['binge'] : 'no_value';
if(is_numeric($q2)){ $q2=number_format($q2,0);}
$q3=isset($_REQUEST['con']) ? $_REQUEST['con'] : 'no_value';
if(is_numeric($q3)){ $q1=number_format($q3,0);}
$q4=isset($_REQUEST['dan_ph']) ? $_REQUEST['dan_ph'] : 'no_value';
if(is_numeric($q4)){ $q1=number_format($q4,0);}
$q5=isset($_REQUEST['childeden']) ? $_REQUEST['childeden'] : 'no_value';
if(is_numeric($q5)){ $q1=number_format($q5,0);}
$q6=isset($_REQUEST['userevie']) ? $_REQUEST['userevie'] : 'no_value';
if(is_numeric($q6)){ $q1=number_format($q6,0);}
$q7=isset($_REQUEST['maze']) ? $_REQUEST['maze'] : 'no_value';
if(is_numeric($q7)){ $q1=number_format($q7,0);}
$q8=isset($_REQUEST['annefrank']) ? $_REQUEST['annefrank'] : 'no_value';
if(is_numeric($q8)){ $q1=number_format($q8,0);}
$q9=isset($_REQUEST['pewds']) ? $_REQUEST['pewds'] : 'no_value';
if(is_numeric($q9)){ $q1=number_format($q9,0);}
$_SESSION['bookrec']=array(
'book1'=>array('callno'=>123005,'price'=>1380,'desc'=>'Attack on Titan Anthology','auth'=>'Scott Synder','quant'=>(int)$q1,'total'=>1380*(int)$q1),
'book2'=>array('callno'=>123006,'price'=>number_format(844,2),'desc'=>'Binge','auth'=>'Tyler Oakley','quant'=>(int)$q2,'total'=>number_format(844,2)*(int)$q2),
'book3'=>array('callno'=>123004,'price'=>number_format(598,2),'desc'=>'A Work in Progress','auth'=>'Connor Franta','quant'=>(int)$q3,'total'=>number_format(598,2)*(int)$q3),
'book4'=>array('callno'=>123003,'price'=>number_format(668,2),'desc'=>'The Amazing Book is Not on Fire','auth'=>'Dan Howell, Phil Lester','quant'=>(int)$q4,'total'=>number_format(668,2)*(int)$q4),
'book5'=>array('callno'=>123002,'price'=>number_format(760,2),'desc'=>'Children of Eden: A Novel','auth'=>'Joey Graceffa','quant'=>(int)$q5,'total'=>number_format(760,2)*(int)$q5),
'book6'=>array('callno'=>123008,'price'=>number_format(799,2),'desc'=>'Username : Evie','auth'=>'Joe Sugg','quant'=>(int)$q6,'total'=>number_format(799,2)*(int)$q6),
'book7'=>array('callno'=>123009,'price'=>number_format(440,2),'desc'=>'The Maze Runner','auth'=>'James Dashner','quant'=>(int)$q7,'total'=>number_format(440,2)*(int)$q7),
'book8'=>array('callno'=>123007,'price'=>number_format(572,2),'desc'=>'Anne Frank: The Biography','auth'=>'Melissa Muller','quant'=>(int)$q8,'total'=>number_format(572,2)*(int)$q8),
'book9'=>array('callno'=>123001,'price'=>number_format(699,2),'desc'=>'This Book Loves You','auth'=>'Pewdiepie','quant'=>(int)$q9,'total'=>number_format(699,2)*(int)$q9)
);
$SESSION['selected']=array();
$selected=$SESSION['selected'];
$b1=implode("<td>",(array)$_SESSION['bookrec']['book1']);
$b2=implode("<td>",(array)$_SESSION['bookrec']['book2']);
$b3=implode("<td>",(array)$_SESSION['bookrec']['book3']);
$b4=implode("<td>",(array)$_SESSION['bookrec']['book4']);
$b5=implode("<td>",(array)$_SESSION['bookrec']['book5']);
$b6=implode("<td>",(array)$_SESSION['bookrec']['book6']);
$b7=implode("<td>",(array)$_SESSION['bookrec']['book7']);
$b8=implode("<td>",(array)$_SESSION['bookrec']['book8']);
$b9=implode("<td>",(array)$_SESSION['bookrec']['book9']);
$bo1=$_SESSION['bookrec']['book1']['total'];
$bo2=$_SESSION['bookrec']['book2']['total'];
$bo3=$_SESSION['bookrec']['book3']['total'];
$bo4=$_SESSION['bookrec']['book4']['total'];
$bo5=$_SESSION['bookrec']['book5']['total'];
$bo6=$_SESSION['bookrec']['book6']['total'];
$bo7=$_SESSION['bookrec']['book7']['total'];
$bo8=$_SESSION['bookrec']['book8']['total'];
$bo9=$_SESSION['bookrec']['book9']['total'];
If(isset($_POST['book1'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book1']){
$selected=$bo1;
$SESSION['selected']=$selected;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b1."</td></tr></table>";
}
}
}
If(isset($_POST['book2'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book2']){
$selected[]=$bo2;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b2."</td></tr></table>";
}
}
}
If(isset($_POST['book3'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book3']){
$selected[]=$bo3;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b3."</td></tr></table>";
}
}
}
If(isset($_POST['book4'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book4']){
$selected[]=$bo4;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b4."</td></tr></table>";
}
}
}
If(isset($_POST['book5'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book5']){
$selected[]=$bo5;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b5."</td></tr></table>";
}
}
}
If(isset($_POST['book6'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book6']){
$selected[]=$bo6;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b6."</td></tr></table>";
}
}
}
If(isset($_POST['book7'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book7']){
$selected[]=$bo7;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b7."</td></tr></table>";
}
}
}
If(isset($_POST['book8'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book8']){
$selected[]=$bo8;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b8."</td></tr></table>";
}
}
}
If(isset($_POST['book9'])){
foreach($_SESSION['bookrec'] as $data){
if($data == $_SESSION['bookrec']['book9']){
$selected[]=$bo9;
echo "<table class='w3-table w3-khaki'><tr><td> ".$b9."</td></tr></table>";
}
}
}
If(empty(isset($_POST['book1'])) && empty(isset($_POST['book2'])) && empty(isset($_POST['book3'])) && empty(isset($_POST['book4'])) && empty(isset($_POST['book5'])) && empty(isset($_POST['book6'])) && empty(isset($_POST['book7'])) && empty(isset($_POST['book8'])) && empty(isset($_POST['book9']))){
echo "<table class='w3-table w3-khaki'><tr><td>No items yet<td></tr></table>";
}
echo "<center><b>TOTAL AMOUNT:</b> Php ".number_format(array_sum((array)$selected),2)."</center>";
?>
무언가 다른 코드를 줄여야합니다. –
Mattia Dinosaur ---- 좋아? 이것에 대한 조사가 끝났지 만 작동하지 않는 것 같습니다. –
코드가 너무 많아서 줄여야합니다. 각 줄을 읽지 않으려 고합니다. –