|
Posted by Jochem Maas on 06/05/05 23:59
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_id
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]
|