SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    865
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Trouble with a dynamically created drop down menu

    The following will make a drop down with each skill it finds in the users table. It will also show the total number in parenthesis. My problem, however, is that the first entry in the drop down menu is (0). All the rest display correctly. What am I missing here?

    Thanks!!


    $findSkills = "select skills, count(*) as total from users where skills != 'None' group by skills order by skills";

    $result = mysql_query ($findSkills) OR die(mysql_error());

    do {

    $skill = $row["skills"];
    $total = number_format($row["total"]);
    $pageContent .= "<option value='$skill'>$skill ($total)</option>";

    } while($row = mysql_fetch_array($result));
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Try with simple while().
    Code:
    while($row = mysql_fetch_array($result)) {
      $skill = $row["skills"];
      $total = number_format($row["total"]);
      $pageContent .= "<option value='$skill'>$skill ($total)</option>";
    }
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    865
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you help me understand what the difference is between the two methods? It looks like the accomplish the same thing.

    Thank you.
    Convert your dollars into silver coins. www.convert2silver.com

  4. #4
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    With do..while(), first it is executed the code from do{..} then the condition from while(). So, in that case, the $row variable used in do{..} not exists for the first iteration because it is created after the while() condition is executed.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners


Bookmarks

Posting Permissions

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