Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey i'm trying to do a for cycle for the number of rows from my query.

$query3="SELECT * FROM carrinho where utilizador = '$utilizador'";
$res1=mysqli_query($lig,$query3);
$num = mysqli_num_rows($res1);


for ($i = 0; $i < $num; $i++) {
$query5 = "SELECT * from carrinho where id_carrinho = '$i'";
$res3=mysqli_query($lig,$query5);
$num1=mysqli_num_rows($res3);

What I have tried:

I tried to echo the number of rows to be sure there are rows, it returns 2.

But when i try to echo $i it returns 0.
Posted
Updated 3-Jul-17 2:35am

1 solution

There's something wrong in your description of the problem. The loop cannot fail so badly. For instance, the following PHP code
PHP
for ($i=0; $i<10; $i++)
{
  $a = "value = '$i'";
  echo $a . "\n";
}

produces the output
value = '0'
value = '1'
value = '2'
value = '3'
value = '4'
value = '5'
value = '6'
value = '7'
value = '8'
value = '9'
 
Share this answer
 
Comments
sarkQ 3-Jul-17 9:42am    
Hmm you're right i've managed to make it work, but my problem seems to be another thing completly different, thanks though!

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