Jump to content

Recommended Posts

Yep, another count question. I have the mySQL part working correctly, but I can't figure out what I'm doing wrong in the php to echo the output. I'm counting all the rows in the table, so I'm not sure why I would need to define an array for the output?

<tags>

$output= mysql_query(select count(*) from email_subscriptions);

echo "Join";

echo "". $output;

echo ""."other users on our mailing list";

<?close tags>

 

I'd like the output to be "Join xxx other users on our mailing list" but I'm getting "Join ResourceID2 on our mailing list"

 

Everything points to an array error, but again I'm not outputting individual rows, I just want to return the overall count of the table. Sorry if this seems really trivial.

You are assigning the RESULT of the query to the variable $output. So, the variable is simply pointing to that result. You need to extract the record(s) from that result as shown by F1Fan. Although, here was my method:

 

$result= mysql_query("SELECT COUNT(*) FROM email_subscriptions");
$count = mysql_result($result, 0);
echo "Join {$count} other users on our mailing list";


Which documentation are you referring to? I think the PHP documentation is excellent.

 

For the mysql_query() function the documentation states in part (emphasis added):

Return Values

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

 

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

 

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

 

The problem with the documentation is that many people don't read all of it (myself included). We read enough to understand the basic usage and then plod ahead from there falling into the same traps that the documentation warned us against.

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.