Re: Filter array results... no copies

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

 



If all you want is a unique list of "adr_one_region" codes, then use the DISTINCT keyword in your SQL:

SELECT DISTINCT adr_one_region FROM egw_addressbook WHERE cat_id='8' ORDER BY adr_one_region


-TG

= = = Original message = = =

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>


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

-- 
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