I have already asked this question here. Run php code conditionally
I have made some modification to the db. The answer given before might be correct , I have tried them but does not work. Those answers might be above my PHP understanding.
Below is rephrased version of the same question.
The actual code that i want to replace
if ($condition1 >= $offer1 AND $condition2 >= $offer2 AND
$condition3 >= $offer3 AND $condition4 >= $offer4 )
{ //run code }
else { //some error messages }
$condition1 and all are numeric value
$offer1 and all are numeric value
I want to replace this code with the new one. sample below.
if ($offercurrent[0]>=$offerpoints[0] AND $offercurrent[1]>=$offerpoints[1] AND
$offercurrent[2]>=$offerpoints[2] AND $offercurrent[3]>=$offerpoints[3] )
{ //run code }
else { //some error messages }
$offerstatus = enabled or disabled
$offercurrent = numeric values
$offerpoints = numeric values
$offercurrent $offerpoints status
50 51 enabled
100 99 enabled
122 865 disable
NNN offern disable
Database values
while($row = mysql_fetch_array($sql))
{
$offername[] = $row['name'];
$offercurrent[] = $row['current'];
$offerstatus[] = $row['status'];
$offerpoints[] = $row['points'];
}
Question:
The code should run only if offerstatus= enabled . one this condition is met . it should check all the occurences of offercurrent and offerpoints.
I have tried to replace the previous code with this one
$check=false;
for ($i=0;$i<count($offerstatus);$i++) {
//echo "$offerstatus[$i]";
if ($offerstatus[$i]=="enabled") {
if($offercurrent[$i]>=$offerpoints[$i]) {$check=true;}
echo "$offername[$i]";}
}
echo "$check";
if ($check=true) { //run code }
else {//error messages}
With this code check alyways return 1 (true) it only checks the first values and ignores the rest of the values.