Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Arrays

Status
Not open for further replies.

neilmurray

Technical User
Jan 18, 2005
32
GB
Hi I have the following snippet of code from a bigger programme.

while ( $row = mysql_fetch_array($result))
{
extract($row);
$l++;
$offerpricecom[$i][$l]=$offerprice;
echo $offerpricecom[$i][$l]; // line 1
}
for ($l==1;$l<=3;$l++)
{ $newprice=$offerpricecom[$i][$l];
echo "$newprice"; //line 2
$query = "select sum(offernumber) from offers where offerprice='$newprice'";
$result = mysql_query($query) or die ("Couldn't execute query2");
while ( $row = mysql_fetch_array($result))
{
echo "$row[0]";
//$num1=$offernumber;
//echo "$num1";
}
}

the code is echoing the correct number for $offerpricecom[$i][$l] on line 1 but then does not echo a number for $newprice on line 2 and hence does not do the query correctly.

What am I not understanding about using arrays?

Thanks,

Neil.
 
You used the wrong operation here:
Code:
for ($l==1;$l<=3;$l++)
You need
Code:
for ($l=1;$l<=3;$l++)
The operator "==" is used for comparison, "=" is used for assignment.

Also, I would not use $l for an index, it is to easy to confuse it with $i.

Ken
 
Two things:

1) If $l is your loop variable in the for loop, why are you incrementing it at the beginning of the while loop?

2) In the for loop, did you mean for the first condition to be $l=1 rather than $l==1? The latter doesn't actually change the value of $l, so the for loop will only ever be executed on the first iteration of the while loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top