Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a while loop that should get values from a mysql database, those values should add using a while loop, However its not working as i expected. all i need to add colom fee values to the variables that i have declared using a while loop.

What I have tried:

<pre><?php
$E03F1="E03F1";
$E03F2="E03F2";
$E03F3="E03F3";
$E03F4="E03F4";
$E03F5="E03F5";
$E03F6="E03F6";
$Fee1="";
$Fee2="";
$Fee3="";
$Fee4="";
$Fee5="";
$Fee6="";

$X=1;

include('db.php');
while($X<=6)
{
   
   $result=mysqli_query($con,"SELECT * FROM toll_fees where feecode='$E03F[$X]'");
    
    while ($row=mysqli_fetch_array($result))
    {
        $Fee[$X]=$row['fee'];
    }
    mysqli_close($con);
    $X++;
}
?> 
Posted
Updated 23-Jul-17 23:20pm

1 solution

1. $Free scoped to the loop, so when you exit the loop the variable is gone...
2. SQL has built in aggregate functions including SUM - use them...
 
Share this answer
 
Comments
Member 13049972 25-Jul-17 3:01am    
but how to declare a variable inside another variable like in C#,

int x=1;
string student;

while(x<=6)
{
print student(x);
x++;
}

Output will be
student 1
student 2 till 6

but in php i cant put

$student[$x] , or how to do this?
Kornfeld Eliyahu Peter 25-Jul-17 3:39am    
That's the exact difference x defined OUTSIDE the loop sot it does not wear out when the scope is gone...
Add '$Fee = [];' before your loop and it should work...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900