SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Zealot backtobasics's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic drop-down menu

    First of all, I know this has been covered many times so sorry to all you's how may roll your eyes!!

    Anyways, I'm trying to load a list of bands names into a drop-down menu, but I can't get it working.

    Currently I'm using:
    PHP Code:
    $result mysql_query"SELECT band_name FROM bands" );
        
    while (
    $row mysql_fetch_array($result))
    {
        
    $bandlist .= "<option value=\"$row[0]\">".$row[1]."</option>\n";
    }
    mysql_free_result($result); 
    Any suggestions?? Thanks

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what, specifically, makes you think that it "doesnt work"?

  3. #3
    SitePoint Zealot backtobasics's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I get a drop-down menu with no data.

  4. #4
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first thing that I spotted are the backslashes in your option tag...I don't think they should be there...
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  5. #5
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what does no data mean? have you viewed your html source? do you get a bunch of <option elements with no value or text?
    when working with php, you should not be looking at how a browser renders something. you should be looking at the html source code it produces.

    one problem is your query selects a single field. this field will be held in $row[0]
    you also try to use $row[1]. did you want to select another field? if so you need to specify it in the query.

    something that may help you is to turn up error reporting when you are debugging
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    php will then notify you when you try to use undefined variables.

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by themightystephen
    The first thing that I spotted are the backslashes in your option tag...I don't think they should be there...
    yes they should. otherwise you would have a parse error.

  7. #7
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have $row[0] in the value but you have $row[1] for what the user sees. Your query only SELECTs one column, bandname, so that is the only item put into the array. Therefore $row[1] doesn't exist.
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  8. #8
    Non-Member
    Join Date
    Apr 2006
    Location
    Scotland
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha co-incidence. Just before I came on sitepoint I was adding 4 sites to Sedo Parking! All of them (were) of bands... just I wanted to park them because I didnt have time to finish them.

    I cant help you, just though it was a coincidence!
    (the sites were bands-in-scotland.com, bandsinscotland.com, scotlandsbands.com and bandsoflondon.com)

  9. #9
    SitePoint Guru themightystephen's Avatar
    Join Date
    Mar 2005
    Location
    England
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by clamcrusher
    yes they should. otherwise you would have a parse error.
    How did I think that!? I'm not with it tonight...don't listen to me...I haven't been doing PHP for a while so I am prone to mistakes!
    Get your heelys now at flywalk.co.uk - But what are heelys?
    Heelys are simply shoes with wheels in the heels!

    Flywalk.co.uk - The UK Heelys Retailer

  10. #10
    SitePoint Zealot backtobasics's Avatar
    Join Date
    Aug 2006
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it working, thanks.


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
  •