Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. populate combo box / dropdown list from mysql

populate combo box / dropdown list from mysql

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpdatabasemysqlquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    komanche
    wrote on last edited by
    #1

    I have been trying hours in to populate combo box with data from a mysql database using php. So far the combo box displays nothing. Anyhelp will be greatly appreciated as the end result I want to have four combo boxes which are based on the first and subsequent selection of each record e.g "country" = "state" = "city" = "suburb" $row[1]\n"; ?>

    L L 2 Replies Last reply
    0
    • K komanche

      I have been trying hours in to populate combo box with data from a mysql database using php. So far the combo box displays nothing. Anyhelp will be greatly appreciated as the end result I want to have four combo boxes which are based on the first and subsequent selection of each record e.g "country" = "state" = "city" = "suburb" $row[1]\n"; ?>

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      komanche wrote:

      $make = "SELECT make FROM cars WHERE make='".$q."' ORDER BY make"; $make = "SELECT id,value FROM make ORDER BY id";

      this sequence of assignments doesn't make sense, either the first is redundant, or something is missing in between them. In future: - please show code snippets inside PRE tags; - for database-related questions explain your tables and fields. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      1 Reply Last reply
      0
      • K komanche

        I have been trying hours in to populate combo box with data from a mysql database using php. So far the combo box displays nothing. Anyhelp will be greatly appreciated as the end result I want to have four combo boxes which are based on the first and subsequent selection of each record e.g "country" = "state" = "city" = "suburb" $row[1]\n"; ?>

        L Offline
        L Offline
        Lucian cornea
        wrote on last edited by
        #3

        Well you should try to find out if the query actually returns something. Try this $dbResID = mysql_query ( $make, $access); if(mysql_errno($access)>0)die("the following sql: $make produced an error: ".mysql_error($access)." "); If there is no error there check to see how many rows have been selected: echo"<p> selected rows:".mysql_num_rows($dbResID)."</p>"; And let us not forget the most important part, the html output(if you did not check it by now) there is something missing. The select tag :) echo'<select name="cars">'; while ( $row = mysql_fetch_row($dbResID) ) print "<option value=\"$row[0]\">$row[1]</option>\n"; echo'</select>'; That is all the debugging that can be done, and if nothing up there works, then there is something really wrong somewhere else. Hope this helps. P.S. Sorry about the fact that part of the code is not displayed right, but I did insert the code tags while writing.

        It can't rain all the time

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups