Udgået syntakt?
Denne syntaks har jeg hidtil brugt i min shop:function get_pris($pid){
$result=mysql_query("select pris from produkter where id=$pid") or die("select pris from produkter where id=$pid"."<br/><br/>".mysql_error());
$row=mysql_fetch_array($result);
return $row['pris'];
}
function remove_product($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
unset($_SESSION['cart'][$i]);
break;
}
}
$_SESSION['cart']=array_values($_SESSION['cart']);
}
function get_vare_antal(){
$max=count($_SESSION['cart']);
$antal=0;
for($i=0;$i<$max;$i++){
$q=$_SESSION['cart'][$i]['qty'];
$antal+=$q;
}
return $antal;
}
function get_order_total(){
$max=count($_SESSION['cart']);
$sum=0;
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$pris=get_pris($pid);
$sum+=$pris*$q;
}
return $sum;
}
function addtocart($pid,$q){
if($pid<1 or $q<1) return;
if(is_array($_SESSION['cart'])){
if(product_exists($pid)) return;
$max=count($_SESSION['cart']);
$_SESSION['cart'][$max]['productid']=$pid;
$_SESSION['cart'][$max]['qty']=$q;
}
else{
$_SESSION['cart']=array();
$_SESSION['cart'][0]['productid']=$pid;
$_SESSION['cart'][0]['qty']=$q;
}
}
function product_exists($pid){
$pid=intval($pid);
$max=count($_SESSION['cart']);
$flag=0;
for($i=0;$i<$max;$i++){
if($pid==$_SESSION['cart'][$i]['productid']){
$flag=1;
break;
}
}
return $flag;
}
men den virker tilsyneladne ikke med php 5.6 og opefter.
Kan nogen hjælpe med en korrekt syntaks på samme søgestrenge?