dug Posted March 5, 2006 Share Posted March 5, 2006 HiHiI have the folloing php code that is not outputing all rows:<?php // create short variable names $username="root"; $password=""; $database="pool"; //connect to server $mysql_connect=mysql_connect("localhost",$username,$password); //select database $mysql_select=mysql_select_db($database) or die( "Unable to select database"); //query database $query = "SELECT SUM(price) AS TOTAL, tabletype FROM ptable WHERE timestamp1>=curdate() GROUP BY tabletype;"; //execute query $result=mysql_query($query); if (!$result){ echo mysql_error();; exit; } //retrieve the query result $num=mysql_numrows($result); if (!$num){ echo 'No match try a another search'; exit; } //display output of rows if($num){ mysql_close(); //loop through result right upto last row for ($i=0; $i < $num; $i++) { $lname=mysql_result($result,$i,"tabletype"); $amountowned=mysql_result($result,$i,"TOTAL"); } } ?> <?php echo $lname;?> <?php echo $amountowned;?> When i run the queryoutside php it produces the right output, 3 rows. Here is the output:+-------+----------------------+| TOTAL | tabletype |+-------+----------------------+| 4.00 | Snooker Championship || 3.50 | Standard Pool || 6.00 | Standard Snooker |+-------+----------------------+But running it on php only outputs the last row. Can anyone helpDug Link to comment https://forums.phpfreaks.com/topic/4150-outputing-rows-problem/ Share on other sites More sharing options...
sjones Posted March 5, 2006 Share Posted March 5, 2006 [quote name='dug' date='Mar 5 2006, 12:23 PM' post='351846']Hi//execute query $result=mysql_query($query); if (!$result){ echo mysql_error();; exit; } //retrieve the query result $num=mysql_numrows($result); if (!$num){ echo 'No match try a another search'; exit; } //display output of rows if($num){ I think there is a syntax error[b]$num=mysql_num_rows($result); //Missing an "_"[/b] Link to comment https://forums.phpfreaks.com/topic/4150-outputing-rows-problem/#findComment-14413 Share on other sites More sharing options...
dug Posted March 5, 2006 Author Share Posted March 5, 2006 Thanks for your reply....No thats not an error....i figuerd that i could not display the output of all rows because i did not store them in a temp array. Got the problem solved though now. Cheers jones Link to comment https://forums.phpfreaks.com/topic/4150-outputing-rows-problem/#findComment-14415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.