Jump to content


Photo

Outputing rows problem


  • Please log in to reply
2 replies to this topic

#1 dug

dug
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 05 March 2006 - 05:23 PM

Hi

Hi

I 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 help

Dug

#2 sjones

sjones
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 March 2006 - 05:34 PM

[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

$num=mysql_num_rows($result); //Missing an "_"

#3 dug

dug
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 05 March 2006 - 05:39 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users