www.webdeveloper.com
Results 1 to 3 of 3

Thread: Avoiding Repeats

  1. #1
    Join Date
    Dec 2005
    Posts
    203

    [RESOLVED] Avoiding Repeats

    Quick question. I'm a table, which might have the same name repeated in several rows, to populate a select list:
    Code:
    $recordset = mssql_query ("select * from purchaseorder order by reqname", $handle);
    while($arr = mssql_fetch_row($recordset))
    {
         $name = $arr[1];
         echo "<option>$name";
    }
    As you can see, if there is more then one entry with the same name the select list will list the name several times.

    I can't seem to think of a way to avoid this, but I know there must be a way.

    For instance:
    Code:
    $recordset = mssql_query ("select * from purchaseorder order by reqname", $handle);
    while($arr = mssql_fetch_row($recordset))
    {
         if($name == '%$totallist%')
         {
              $name = $arr[1];
              echo "<option>$name";
         }
         $totalnames = "$totalnames $name";
    }
    Although I know my if statment is not valid, how do you pros do it?
    Last edited by Doc Thirst; 08-10-2006 at 12:46 PM.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,355
    PHP Code:
    $recordset mssql_query ("SELECT DISTINCT reqname FROM purchaseorder ORDER BY reqname"$handle);
    while(
    $arr mssql_fetch_row($recordset))
    {
         echo 
    "<option>".$arr[0]."</option>\n";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Dec 2005
    Posts
    203
    Ugg, soooo easy, I'm a tool. Thanks once again NogDog

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles