Jump to content

Archived

This topic is now archived and is closed to further replies.

dug

Outputing rows problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.