Jump to content

Outputing rows problem


dug

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
Link to comment
https://forums.phpfreaks.com/topic/4150-outputing-rows-problem/
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]
Link to comment
https://forums.phpfreaks.com/topic/4150-outputing-rows-problem/#findComment-14413
Share on other sites

Archived

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

×
×
  • Create New...

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.