|
Posted by "M. Sokolewicz" on 06/06/05 00:50
Jack Jackson wrote:
> Thanks for all the replies. Jochem, thank you for this code, which will
> take me all night to understand (though I bet it works). I also note
> that SELECT DISTINCT worked here, too
>
> Also as many of you noticed before me, the art_id was in there as a fly
> in the ointment.
by that statement I ment the exact same thing Jochem ment in his 2nd
part; I have NO idea why you're selecting *ANYTHING* from the arts
table... it's *useless* if you don't need the data...
>
> Thanks all!
>
>
>
> Jochem Maas wrote:
>
>> Jack Jackson wrote:
>>
>>> This is something dumb I am doing but:
>>>
>>> Trying to pull all names of publishers in db. This sql:
>>>
>>
>> its a mysql question in disguise, maybe...:
>>
>> SELECT DISTINCT art.art_id,art.publisher_id,publisher.publisher_name
>> FROM art
>> LEFT JOIN publisher
>> ON publisher.publisher_id=art.publisher_iduse,
>> on the other hand if you want to pull every article
>> from the DB then that won't do it. maybe you
>> need to be extracting the name of the article instead/aswell?
>>
>> on the other hand if you are trying to display a list of
>> publishers, why are you selecting from the arts table?
>>
>> SELECT p.publisher_id,p.publisher_name
>> FROM publisher p ORDER BY p publisher_id DESC
>>
>> (maybe you only want to show publishers with listed 'art's?)
>>
>> what does this do for you?:
>>
>> SELECT COUNT(a.art_id) as art_count,a.publisher_id,p.publisher_name
>> FROM art a, publisher p
>> WHERE p.publisher_id=a.publisher_id
>> AND art_count > 0
>> GROUP BY a.publisher_id
>>
>>> SELECT art.art_id,art.publisher_id,publisher.publisher_name,
>>> FROM art
>>> LEFT JOIN publisher
>>> ON publisher.publisher_id=art.publisher_id
>>>
>>> pulls (in phpmyadmin) four rows:
>>> artID pubID Publisher_name
>>> 1 7 The New York Times: Sunday Styles
>>> 2 3 The New York Sun
>>> 3 2 Metro NY
>>> 4 3 The New York Sun
>>>
>>>
>>> I'm trying to make a sidebar which will make links to each unique
>>> publisher name:
>>>
>>
>> and/or something like.:
>>
>> <?php
>>
>> // $result = DB::doMagic();
>>
>> $seenAlready = array();
>> $templet = '<ul class="sidebar-menu"><a class="img-link" href="'
>> . $_SERVER['PHP_SELF']
>> . '?p=%1$s" title="%2$s">%2$s</a></ul>';
>>
>> while ($cartoon = mysql_fetch_assoc($result)) {
>> if (in_array($cartoon['publisher_id'], $seenAlready))
>> continue;
>>
>> $seenAlready[] = $cartoon['publisher_id'];
>> $pub_sidebar[] = sprintf($templet,
>> $cartoon['publisher_id'],
>> $cartoon['publisher_name']);
>> }
>>
>>> while ($cartoon = mysql_fetch_assoc($result)) {
>>> $pub_sidebar[] = "<ul class='sidebar-menu'><a class='img-link'
>>> href='{$_SERVER['PHP_SELF']}?p={$cartoon['publisher_id']}'
>>> title=\"{$cartoon['publisher_name']}\">{$cartoon['publisher_name']}</a></ul>";
>>>
>>> }
>>>
>>>
>>> This prints:
>>> The New York Times: Sunday Styles
>>>
>>> The New York Sun
>>>
>>> Metro NY
>>>
>>> The New York Sun
>>>
>>>
>>> I'd like to stop the NY Sun from appearing twice! What have i missed
>>> here?
>>>
>>> Thanks in advance!
>>>
>>
>>
>>
Navigation:
[Reply to this message]
|