distinct result using php & mysql

From: Date: Tue, 05 Dec 2000 11:22:30 +0000
Subject: distinct result using php & mysql
Groups: php.general 
Request: Send a blank email to php-general+get-28704@lists.php.net to get a copy of this message
hello everybody, Here is a piece of code I am writting with PHP 4 using MySQL 3.23 and Apache 1.3.12 My problem is that I store data in a field of my database where the data is separated by commas and contain more than one word. I want to print the result of the query with only one word for each <a href> I have replaced the commas by spaces, explode the string for each individual result and then looped through the results BUT now my problem is to make sure that there will be only one line printed for each different result and not all the results contained in the database, i.e $resultrow[0] == apple, peach, orange, $resultrow[1] == apple, lemon, kiwi , how to I make sure that the second "apple " will not be printed? Thanks in anticipation code: $query ="SELECT * FROM nom_table WHERE field1= 'x'"; $result = mysql_query($query); $number = mysql_numrows($result); for ($g=0;$g<$number; $g++) { $field = mysql_result($result, $g, "field"); $filed = str_replace(",", " ", $field); $resultrow = explode (" ", $field); for ($i=0; $i<count($resultrow); $i++) { if ($resultrow[$i]!=='') { $query2 = mysql_query ("SELECT COUNT(*) FROM nom_table WHERE field LIKE '%$resultrow[$i]%' OR field2 LIKE '%$resultrow[$i]%'"); $y = mysql_fetch_array ($query2); PRINT "&nbsp;<a href='page.php3?search=$resultrow[$i]' target=\"main\">$ADfont_style_current_vacancy_links $resultrow[$i]</a>($no_skill_one[0] results)<br>\n"; } } }

« previous php.general (#28704) next »