Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.