MySQL Forums
Forum List  »  Newbie

Re: Newbie question
Posted by: Nick Roper
Date: August 07, 2004 03:36AM


First of all, what you're looking at here isn't MySQL syntax - it's PHP, which is a programming language that is widely used to expose information in a MySQL database via a web-browser.

Anyway, to answer your questions:

mysql_result() is a PHP function that can be used to fetch data from a specific field(column) in a recordset. It takes three parameters which, in the context of your example, are as follows:

$sql - the result set returned by mysql_query()
$x - a pointer to a row number in the recordset
"subcategories" - the field/column name from which to get the data on that row

So, in this example, a for loop is being used to retrieve data from the "subcategories" field for rows 0 to $n_subcategories (which presumably is being assigned elsewhere?) of the recordset.

As for the LEFT JOIN, the join is actually on a table named (something)categories.

The syntax '... {$prefix}categories AS {$prefix}subcategories ..." does the following:

Suppose that the $variable contained 'foo', this would be substituted into the string as follows:

'... foocategories AS foosubcategories ..."

'foosubcategories' then becomes an alias for the real table name, and can be used elsewhere.

Variable sunstitution in PHP works within "" "" quoted string, so "my name is $name" will return (say) "my name is Nick" if $name is 'Nick'. However, a problem occurs if you try to prepend or append a variable name to a literal string, for example, if you had 'Sun' stored in a variable called $shortname, and then tried to display the full day name with: "Today is $shortnameday " (to get 'Sunday'), PHP would actually see the variable name as '$shortdayname' - which doesn't exist. To get round this { } brackets are used to isolate the variable name and force a substitution, i.e: "Today is {$shortname}day "

Hope this hepls,


Nick Roper

Options: ReplyQuote

Written By
August 06, 2004 11:01PM
Re: Newbie question
August 07, 2004 03:36AM
August 07, 2004 03:56AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.