Jump to content


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


Trouble understanding MySQL Syntax

Recommended Posts

Hey people,

I am trying to figure out what this means:

[code]$sql = sprintf("SELECT COUNT(*) AS test FROM %s WHERE email = '%s' OR login = '%s'", $this->table_name, $this->user_email, $this->user);

I have searched through my PHP book (by Eric Rosebrock) and searched the MySQL docs, but I cannot figure out, specifically, what the following are:

[ol type=\'1\'][*]What is [code]AS Test[/code] referring to?[*]What is the purpose of [code]%s[/code]?[/ol]
If someone could explain these two questions I will be greatful.

Thanks- for putting up with a [i]newb[/i],
Scott G.

Share this post

Link to post
Share on other sites
[a href=\"http://www.php.net/sprintf\" target=\"_blank\"]sprintf()[/a] replaces %s with the variables supplied in the second parameter, in the order they are provided. So "FROM %s" will turn into "FROM $this->table_name".

The "COUNT(*) AS test" is a way of getting the number of rows returned, and it will be returned in a column called "Test", there should be something in the manual under SELECT about it

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.