List:General Discussion« Previous MessageNext Message »
From:-Patrick Date:April 29 2006 3:47am
Subject:Re: Matching fields from two different tables
View as plain text  
John Hicks wrote:
> -Patrick wrote:
>> Folks, I could really use your assistance.
>> Take a look here: http://pastebin.com/687889
>>
>> How can I manipulate totalRows_numberComments so that I get the number
>> of blg_comment_com.idart_com PER blg_article_art.id_art? Right now, it
>> produces every blg_comment_com.idart_com in existence, definately not
>> cool.
>>
>> Thanks
>> -Patrick
>>
>
> You had:
> SELECT COUNT(*) FROM blg_comment_com, blg_article_art WHERE
> blg_article_art.id_art=blg_comment_com.idart_com
>
> Try this:
>
> SELECT blg_article_art.id_art, COUNT(*) as NumberOfComments
> FROM blg_comment_com, blg_article_art
> WHERE blg_article_art.id_art = blg_comment_com.idart_com
> group by blg_article_art.id_art
>
> Try it in the mysql console before you try to plug it into php.
> (You can only learn so much at one time :)
>
> --John
>
>
That is fantastic John. Outputs the id along with respective count.

However, it leads back to my original question... how do I coordinate
the output from this query with php? I know php fairly well, but when
mixes with mysql Im still new and I only want to call those particular
values and have them respond appropriately. What do you suggest? Take
this output and shove it into an array, and match up id_art with a <?
echo arrayNum['id_art']; ?> ? Say, if NumberOfComments > 0, echo
NumberOfComments? See, I can output the NumberOfComments, but they're
either a total of the whole db and/or constant for every id_art.. even
though the query output is correct? (also derived a similar output but
used a different query... same problem resides -coordination).

Any suggestions are appreciated,
Thank you
-Patrick
Thread
Matching fields from two different tables-Patrick29 Apr
  • Re: Matching fields from two different tablesJohn Hicks29 Apr
    • Re: Matching fields from two different tables-Patrick29 Apr
      • Re: Matching fields from two different tablesJohn Hicks29 Apr