farahZ Posted May 19, 2013 Share Posted May 19, 2013 hello, i am trying to print the query $result, each in a row!! but i am just getting the form of the table without values added to it.. the query works fine since it was outputting normally before adding the table code any help !! $result = mysqli_query($con, $sql) or die(mysqli_error()); $num_rows = mysqli_num_rows($result); while ($row = mysqli_fetch_array($result) && $i<$num_rows) { ?> <tr> <td><?php echo $row['DayTime'];?></td> <td><?php echo $row['Calories'];?></td> </tr> </table> <?php $i++; } Quote Link to comment Share on other sites More sharing options...
Solution yomanny Posted May 19, 2013 Solution Share Posted May 19, 2013 You're ending the table with </table> inside of the while-loop but you don't start any <table> in the loop. Might that be the problem? Move </table> outside of the loop and make sure there's a <table> tag before the loop aswell. Also, you can remove this condition: && $i<$num_rows The loop will stop when it's gone through the results from the query. - W Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 19, 2013 Author Share Posted May 19, 2013 i tried that, its now creating rows but not filling them!! thats the code i reached <?php $num_rows =''; $i=0; $date =$_POST['dates']; $sql="SELECT fe.DayTime, SUM(f.Calories) as Calories FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date='$date' GROUP BY fe.DayTime"; $result = mysqli_query($con, $sql) or die(mysqli_error()); //var_dump($sql); $num_rows = mysqli_num_rows($result); ?> <table width="800" border="3"> <tr> <th bgcolor="#77eb8a" height="25" scope="col">Meal</th> <th bgcolor="#77eb8a" scope="col">Calories</th> </tr> <?php while ($row = mysqli_fetch_array($result) && $i<$num_rows) { ?> <tr> <td><?php echo $row['DayTime'];?></td> <td><?php echo $row['Calories'];?></td> </tr> <?php $i++; } ?></table> <?php $sql1="SELECT SUM(f.Calories) as Calories FROM fooddiary fe INNER JOIN food f USING (Food) WHERE fe.ID= 111 And fe.Date='$date'"; $result1 = mysqli_query($con, $sql1) or die(mysqli_error()); $row = mysqli_fetch_array($result1); echo 'The total Calories for this day is ' . $row['Calories']; mysqli_close($con); } Quote Link to comment Share on other sites More sharing options...
farahZ Posted May 19, 2013 Author Share Posted May 19, 2013 done.. by removing the num_rows!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.