how to Select unique values in arrays
Posted: Thu May 19, 2005 4:37 am
Hi, i have done this to retrive the name from a string containing different info.
it give me this :
And what i need to have is the unique values for server,
so it will fill a drop down menu with
leaving out the values that does not contain "server".
For this i was going through the substring function, but as i've written on the sript "i'm lost" after this step...
Thanks all...
Code: Select all
$db = mysql_connect("localhost", "root", "");
// Select DB
mysql_select_db("Support",$db);
$query_name = mysql_query("select distinct transaction_name from kpi");
while ($testname = mysql_fetch_array($query_name))
{
foreach ($testname as $name)
{
$new_filename = str_replace('_', ' ', $name);
$filenames_ord = preg_split("/\s/", $new_filename);
//reverse order to pick up server name
$filenames_rev = array_reverse($filenames_ord);
//check if the string contains "server"
$filenames_comp = substr($filenames_rev[0], 0, 6);
//!!! Here i'm lost... !!!
//check result for testing
echo "<pre>";
echo $filenames_rev[0];
}
}Code: Select all
comp
comp
cartBuyer
cartBuyer
cep
cep
cart
cart
server50
server50
server52
server52
server58
server58
server50
server50
server52
server52
server58
server58
server50
server50
server52
server52
server58
server58
server50
server50
server52
server52
server58
server58so it will fill a drop down menu with
Code: Select all
server50
server52
server58For this i was going through the substring function, but as i've written on the sript "i'm lost" after this step...
Thanks all...