Site maintenance: Sun 15 Nov, from 12:00 UTC, about 4–6 hours. Details

This cutover relies on some testing that is still incomplete so may be cancelled at short notice

Forums / Contribution-Writing Guidelines / question about $sql statements

question about $sql statements

Started by tcarden on 22 Dec 2012, 9:48 PM · Views: 2,194

Results 1 to 4 of 4
22 Dec 2012, 9:48 PM
#1
tcarden avatar

tcarden

Zen Follower

Join Date:
Oct 2012
Posts:
282
Plugin Contributions:
0

question about $sql statements

via a client's request, i'm adding a 'features list' to the products table.

right now i just have question about the Query found in 'main_template_vars.php'

the query is this:
select count(*) as total from zen_products p, zen_products_description pd .....etc.

what does the 'p' and the 'pd' mean following the table names??, unfamiliar w/ such a syntax.

thanks!

22 Dec 2012, 10:01 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,134
Plugin Contributions:
56

Re: question about $sql statements

tcarden:

the query is this:
select count(*) as total from zen_products p, zen_products_description pd .....etc.

what does the 'p' and the 'pd' mean following the table names??, unfamiliar w/ such a syntax.

thanks!
The construct zen_products p, zen_products_description pd defines a 'shorthand notation' that will be used in the query. Further in the query, you might find some variables referenced as p.products_id and pd.products_id which refer to the products_id field in the products table and the same field in the products_description table, respectively.

22 Dec 2012, 10:17 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

Re: question about $sql statements

lat9 is correct.
Those are table "alias"es.
p.products_id (when p is defined by zen_products in your example) is much easier to write and read than zen_products.products_id
especially when you get into writing WHERE and JOIN clauses such as
WHERE zen_products.products_id=zen_products_description.products_id AND zen_products_description.language_id = 1 .... etc
vs just
WHERE p.products_id=pd.products_id and pd.language_id=1 ... etc

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

27 Dec 2012, 2:51 AM
#4
tcarden avatar

tcarden

Zen Follower

Join Date:
Oct 2012
Posts:
282
Plugin Contributions:
0

Re: question about $sql statements

aye, yes!, a belated thank you.

i remembered after my posting that it is shorthand, thanks