Re: Filter array results... no copies

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matthew Ferry wrote:

> Hello everyone....
> 
> I'm back working on the website again... I'm having lots of fun.
> I have a sql query that looks at one field in a database. (result2 query)
> Then i have mysql_fetch_array statement.
> 
> I then use this array to print links on the page.
> Works fine except I don't want duplicate links.
> 
> It creates links for the states.  If we have four customers from
> Pennsylvania.  This current process gives me four different "PA" links on
> my page.
> 
> I need a statement that says...if its already printed...don't print it...
> 
> Thanks...
> 
> Here is my code:
> 
> <html>
> 
> <body>
> 
> <?php
> 
> $db = mysql_connect("HOST", "USERNAME", "PASSWORD");
> 
> mysql_select_db("DATABASE",$db);
> 
> 
> if ($_GET[area]=="") {
> 
> $master = mysql_query("SELECT * FROM egw_addressbook
> 
> WHERE cat_id='8' ORDER BY org_name", $db);
> 
> 
> 
> } else {
> 
> $master = mysql_query("SELECT * FROM egw_addressbook
> 
> WHERE cat_id='8' and adr_one_region='$_GET[area]' ORDER BY org_name",
> $db);
> 
> }
> 
> 
> 
> $result2 = mysql_query("SELECT adr_one_region FROM egw_addressbook
> 
> WHERE cat_id='8' ORDER BY adr_one_region", $db);
> 
> 
> 
> if ($area = mysql_fetch_array($result2)) {
> 
> echo "Sort by State: ";
> 
> 
> 
> do {
> 
> echo "<a
> href='index.php?area=$area[adr_one_region]'>$area[adr_one_region]</a>\n";
> 
> echo " - ";
> 
> } while ($area = mysql_fetch_array($result2));
> 
> echo "<a href='index.php?area='>ALL</a>\n";
> 
> } else {
> 
> echo "ERROR";
> 
> }
> 
> 
> 
> if ($myrow = mysql_fetch_array($master)) {
> 
> echo "<CENTER>\n";
> 
> echo "<table border=0>\n";
> 
> echo "<img src=file.jpg width='611' height='136'>\n";
> 
> echo "<BR>\n";
> 
> echo "<BR>\n";
> 
> 
> 
> do {
> 
> printf("<tr>
> <td></td><td><b>%s</b></td><td></td><td></td><td>%s</td></tr>\n",
> $myrow["org_name"], $myrow["fn"]);
> 
> printf("<tr> <td></td><td>%s</td><td></td><td></td><td>%s</td></tr>\n",
> $myrow["adr_one_street"], $myrow["tel_work"]);
> 
> printf("<tr> <td></td><td>%s, %s
> %s</td><td></td><td></td><td></td><td></td></tr>\n",
> $myrow["adr_one_locality"], $myrow["adr_one_region"],
> $myrow["adr_one_postalcode"]);
> 
> 
> 
> } while ($myrow = mysql_fetch_array($master));
> 
> echo "</table>\n";
> 
> echo "</CENTER>\n";
> 
> } else {
> 
> echo "Sorry, no records were found!";
> 
> }
> 
> ?>
> 
> </body>
> 
> </html>

Hm, perhaps if you order by state first, then do something like (pseudocode
only):

set currentstate = ''; # Initialise variable to empty
while (looping through result set)
  if currentstate != state_from_dataset
    echo $state
  endif
  display other stuff
  do any other stuff in loop
  set currentstate = state_from_dataset
endwhile



Cheers
-- 
David Robley

Auntie Em: Hate you, hate Kansas, taking the dog. -Dorothy
Today is Boomtime, the 12nd day of Chaos in the YOLD 3173. 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux