Jump to content

Trouble understanding MySQL Syntax


scott532

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);
[/code]


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.
Link to comment
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
Link to comment
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.