Jump to content

Resource Id #16 Error


colinjack

Recommended Posts

When I run this

<?phpinclude 'config.php';include 'opendb.php';mysql_select_db ('kenfest', $conn);	$result = mysql_query("SELECT * FROM register");	$total_tickets = mysql_query("SELECT sum(tickets) FROM register");		 $numrows = mysql_num_rows($result);		echo "There are $numrows people registered:<BR />";	echo "Total tickets requested: $total_tickets <br />";?>

I get:There are 10 people registered:Total tickets requested: Resource id #6 but if I run the same query from the mysql CLI I get the correct result.What am I missing?I've just started playing with PHP so PLEASE be patient with me!

Link to comment
Share on other sites

I found that and other similar one's on the web but that isn't quite what I want.I want a total sum of all the values of the 'tickets' field. The database allows people to register to request tickets (up to 10 per person). I just want to return a running total of tickets.This works from the CLI:mysql> select sum(tickets) from register;+--------------+| sum(tickets) |+--------------+| 97 |+--------------+1 row in set (0.00 sec)mysql>but not from within the script.Thanks.
Link to comment
Share on other sites

$total_tickets = mysql_query("SELECT sum(tickets) FROM register");$total_tickets is not going to be the number, it's going to be a recordset like any other call to mysql_query. You still need to get the row (there should only be one), and then you can get the value from the row.

Link to comment
Share on other sites

$total_tickets = mysql_query("SELECT sum(tickets) FROM register");$total_tickets is not going to be the number, it's going to be a recordset like any other call to mysql_query. You still need to get the row (there should only be one), and then you can get the value from the row.
Doh - just realised what I've written. :) Back to the manual. Thanks for the pointer.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...