Re: looping through an array problem
| From: | Jack Jackson | Date: | Sun, 05 Jun 2005 21:09:18 +0000 |
| Subject: | Re: looping through an array problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-216437@lists.php.net to get a copy of this message | ||
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.
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_idSELECT 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:and/or something like.: <?php // $result = DB::doMagic(); $seenAlready = array();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 SunI'm trying to make a sidebar which will make links to each unique publisher name:$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 StylesThe New York SunMetro NYThe New York SunI'd like to stop the NY Sun from appearing twice! What have i missed here? Thanks in advance!