I was looking for the script like below to collect field record in combo box but couldn’t find so I spend 3 hours to make a script which can retrieve the data from mysql table to combo box without creating duplicates.
e.g
(MySQL - Data)
(require data)
ID
1
2
3
4
5
6
7
(Out - Data)
cat.product
nokia
ezkez.com
Imran
Shabir
(Source Code)
[PHP]
require_once('c onnection.php') ;
$data = mysql_query("SE LECT * FROM table") or die(mysql_error ());
while ($ar = mysql_fetch_arr ay($data))
{
//specify the index of $array here really depends on how it's structured
$dtx[] = $ar['cat.product'];
}
//get all cat.product data from mysql table
$array = $dtx;
//get unique list from array
$unique = array_unique($a rray);
echo "<select>";
//create each field
foreach($unique as $unique)
{
echo "<option name='$unique'> $unique</option>";
}
echo "</select>";
[/PHP]
Hope this may help some one.
Imran Nawab Khan
e.g
(MySQL - Data)
(require data)
ID
cat.product
click1
nokia
22
ezkez.com
13
Imran
14
Shabir
85
nokia
56
ezkez.com
687
Imran
5(Out - Data)
cat.product
nokia
ezkez.com
Imran
Shabir
(Source Code)
[PHP]
require_once('c onnection.php') ;
$data = mysql_query("SE LECT * FROM table") or die(mysql_error ());
while ($ar = mysql_fetch_arr ay($data))
{
//specify the index of $array here really depends on how it's structured
$dtx[] = $ar['cat.product'];
}
//get all cat.product data from mysql table
$array = $dtx;
//get unique list from array
$unique = array_unique($a rray);
echo "<select>";
//create each field
foreach($unique as $unique)
{
echo "<option name='$unique'> $unique</option>";
}
echo "</select>";
[/PHP]
Hope this may help some one.
Imran Nawab Khan
Comment