Code: Select all
SELECT * FROM article_categories LEFT JOIN article_subcat ON article_categories.category_id = article_subcat.category_id
AND article_subcat.category_id = '$sec' ORDER BY article_categories.category_order ASCThank-you
Moderator: General Moderators
Code: Select all
SELECT * FROM article_categories LEFT JOIN article_subcat ON article_categories.category_id = article_subcat.category_id
AND article_subcat.category_id = '$sec' ORDER BY article_categories.category_order ASCCode: Select all
SELECT * FROM article_categories LEFT JOIN article_subcat ON article_categories.category_id = article_subcat.category_id
WHERE article_subcat.category_id = '$sec' ORDER BY article_categories.category_order ASCWow that's almost as ambiguous as my orginal post.Weirdan wrote: ?
Code: Select all
table 1 article_categories ---|--- table 2 article_subcat
-------------------------------------------------------------------
key - category_id ---|--- key - subcat_id
category_name ---|--- subcat_name
category_description ---|--- category_id
category_order ---|--- subcat_descriptionCode: Select all
while ($row = $db->sql_fetchrow($result)){Code: Select all
Array (
ї0] => 1
їcategory_id] => 1
ї1] => Online Education
їcategory_name] => Online Education
ї2] => education programs for adults.
їcategory_description] => education programs for adults.
ї3] => 2
їcategory_order] => 2
ї4] => 2
їsubcat_id] => 2
ї5] => Enrollment
їsubcat_name] => Enrollment
ї6] => prices and costs associated with the university
їsubcat_description] => prices and costs associated with the university
ї7] => 1
)Code: Select all
Array (
ї0] => 4
їcategory_id] =>
ї1] => About RWU
їcategory_name] => About RWU
ї2] => This category contains our mission statement and purpose statements.
їcategory_description] => This category contains our mission statement and purpose statements.
ї3] => 1
їcategory_order] => 1
ї4] =>
їsubcat_id] =>
ї5] =>
їsubcat_name] =>
ї6] =>
їsubcat_description] =>
ї7] =>
)because in this case the value has been taken from second table where you have similary named field (which is null because of left join)neophyte wrote: The question is why does [0] have a value but ['category_id] does not....
It's ok, often I do not elaborate enough as wellneophyte wrote: Sorry I didn't mean to be short in my description. It's hard sometimes to know when you've given too little information and when you've been to verbose.
Code: Select all
SELECT
c.category_id,
c.category_name,
c.category_description,
c.category_order,
s.subcat_id,
s.subcat_name,
s.subcat_descriptions
FROM
article_categories c
LEFT JOIN
article_subcat s
ON
c.category_id = s.category_id
AND s.category_id = '$sec'
ORDER BY
c.category_order ASCthey are aliases for the table names. I do not follow <table name>_<field_name> notation for fields, hence I used to use aliases.neophyte wrote: I'm just wondering what the "c." and "s." do in the query?
I just prefer it to be this wayneophyte wrote: Why did you re-label the table names in the FROM and LEFT JOIN statement with a and ending "c" and and ending "s"?