/    Sign up×
Community /Pin to ProfileBookmark

array problem

Hi all,

I am facing a problem of arrays.The fact is that I am getting the array values but when i am running 2 arrays under a single for loop then I am only getting null values for the quantities….lets give you the code so that you can understand where the problem lies.

output of
echo “Key1: $key1; Value1: $value1<br />n”;
echo “Key2: $key2; Value2: $value2<br />n”;

is

Key1: 0; Value1: 1475
Key2: 0; Value2:
insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘1′,’1475′,”,’180.05′,’0’)
Key1: 1; Value1: 1476
Key2: 1; Value2:
insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘1′,’1476′,”,’196.74′,’0’)
Key1: ; Value1:
Key2: 2; Value2: 3
Key1: ; Value1:
Key2: 3; Value2: 5

As you see I am not getting the net_total and quantity

[code=php]//if the form is submitted
if(isset($_POST[‘image1_x’]))
{
$pid=$_POST[‘pid’];//product id
$quantity=$_POST[‘quantity’];
$item_price=$_POST[‘item_price’];
if($pid!=””)
{
for(
;
list($key1, $value1 ) = each( $pid ) ,
list($key2, $value2 ) = each( $quantity )
;
) {
echo “Key1: $key1; Value1: $value1<br />n”;
echo “Key2: $key2; Value2: $value2<br />n”;
foreach($item_price as $k=>$v)
{
list($v1,$v2)=explode(“#”,$v);//(price and pid)

if($value1!=””)
{
if($v2==$value1)//if pid==pid
{
$net_total=$value2*$v1;
$s_pro=”select pid from temp_cart where pid=’$value1′ and cart_id=’$cart_id'”;// TO SEE IF THE SELECTED PRODUCT IS ALREADY IN THE CART OR NOT

$q_pro=mysql_query($s_pro) or die(mysql_error());
$numrows=mysql_num_rows($q_pro); if($numrows==””)
{
//echo “insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘$cart_id’,’$value1′,’$value2′,’$v1′,’$net_total’)”;
$s_temp=”insert into temp_cart(cart_id,pid,quantity,item_price,net_total) values(‘$cart_id’,’$value1′,’$value2′,’$v1′,’$net_total’)”;
$q_temp=mysql_query($s_temp) or die(mysql_error());
header(“location:cart.php”);
}
else
{
$err=1;//one of the selected product is already in the cart
}
}
}
}
}
}
else
{
$emp=1;//no product has been selected
}
}[/code]

[code=html]//html form
<form name=”form1″ method=”post” action=””>
<table width=”95%” align=”center” cellpadding=”3″ class=”table”>
<tr>
<td width=”25%” class=”text” align=”center”>
<?=$icode;?>
</td>
<td width=”12%” class=”text” align=”center”>
<?=$design;?>
</td>
<td width=”9%” class=”text” align=”center”>
<input type=”text” name=”quantity[]” value=”” size=”7″>
</td>
<td width=”9%” class=”text” align=”center”>
<input type=”checkbox” name=”pid[]” value=”<?=$pid;?>”>
</td>
<td width=”10%” class=”text” align=”center”>
<?=$list;?>
</td>
<input type=”hidden” name=”item_price[]” value=”<?=$list.”#”.$pid;?>”>
</tr>
<tr>
<td colspan=”9″ class=”Subtitle” align=”center”>
<input type=”image” img src=”images/addtocart.gif” width=”85″ height=”17″ name=”image1″ value=”up”>
</td>
</tr>
</table>
</form>[/code]

Please suggest how to get the values from the quantity array

Thanks in advance for your co-operation.
Raj

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @raj_2006 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...