Jump to content


Photo

Trouble understanding MySQL Syntax


  • Please log in to reply
2 replies to this topic

#1 scott532

scott532
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationSanta Barbara, CA. (USA)

Posted 14 May 2006 - 12:07 AM

Hey people,

I am trying to figure out what this means:

$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
AS Test
referring to?[*]What is the purpose of
%s
?[/ol]
If someone could explain these two questions I will be greatful.

Thanks- for putting up with a newb,
Scott G.

#2 Carth

Carth
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationUK

Posted 14 May 2006 - 12:34 AM

[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

#3 scott532

scott532
  • Members
  • PipPip
  • Member
  • 14 posts
  • LocationSanta Barbara, CA. (USA)

Posted 14 May 2006 - 12:41 AM

Thanks Carth, i get it now.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users