How to make dynamic combo box without creating duplicates with PHP and MySql?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imrannawabkhan
    New Member
    • Sep 2007
    • 4

    How to make dynamic combo box without creating duplicates with PHP and MySql?

    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
    cat.product
    click
    1
    nokia
    2
    2
    ezkez.com
    1
    3
    Imran
    1
    4
    Shabir
    8
    5
    nokia
    5
    6
    ezkez.com
    68
    7
    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
  • imrannawabkhan
    New Member
    • Sep 2007
    • 4

    #2
    Make dynamic combo box without creating duplicates with PHP and MySql?

    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)

    ID--------cat.product--------click
    1---------nokia-------------------2
    2---------ezkez.com-----------1
    3---------Imran-------------------1
    4---------Shabir------------------8
    5---------nokia-------------------5
    6---------ezkez.com-----------68
    7---------Imran-------------------5

    "-------" ignore the lines this is to show u the proper table.

    (Output - Data of cat.product field)
    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

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      This is a Q&A forum - Questions and Answers. Seeing as this is neither, I will relunctantly move it to the 'editors corner', once you have replied and acknowledged my post.

      Moderator.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Apparently you've already posted this in the editors corner.

        Please read your PMs



        -- Threads merged

        Comment

        Working...