Results 1 to 4 of 4

Thread: Combo box

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Combo box

    If I submit some variables to a php page. How can I get the values into a combobox. Isn't the combo box declared in HTML? So how do I get the variables there....or is there something that I don't know about here?

  2. #2

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    This does not seem to work, and I am not surprised...just had to test...


    Code:
    <select name="sNavn" >
    						<?php
    
    							$db=mysql_connect ("localhost", "klub_note", "motvekt") or die ('I cannot connect to the database because: ' . mysql_error());
    							mysql_select_db ("klub_info");
    
    							if (!$db){
    								echo 'I cannot connect to the database because: ' . mysql_error();
    								exit;
    							}
    
    							mysql_select_db ("klub_info");
    
    
    							$resultat = mysql_query("SELECT sNavn FROM Sted",$db);
    
    							$innkode = mb_internal_encoding();
    
    							while ($rekke = mysql_fetch_array($resultat)) {
       								mb_convert_variables($innkode, "ASCII, UTF-8, ISO-8859-1", $rekke);
       								$id = $rekke["id"];
       								$sNavn = stripslashes($rekke["sNavn"]);
    								?>
    								<option value="<?php sNavn ?>"><?php sNavn ?></option> <?php
    							}
    						?>
    					</select>

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    uh, well, first off your code doesn't get submitted variables and put them into a combo box, it takes stuff from a MySQL database.. so, I'll just build around that.

    PHP Code:
    <select name="opt">
    <?
      $qry = mysql_query("SELECT snavn FROM sted");
      while($arr = mysql_fetch_array($qry)){
        echo "  <option value=\"$arr[snavn]\">$arr[snavn]\n";
      }
    ?>
    </select>
    Like Archer? Check out some Sterling Archer quotes.

  4. #4

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by kows
    uh, well, first off your code doesn't get submitted variables and put them into a combo box, it takes stuff from a MySQL database.. so, I'll just build around that.

    PHP Code:
    <select name="opt">
    <?
      $qry = mysql_query("SELECT snavn FROM sted");
      while($arr = mysql_fetch_array($qry)){
        echo "  <option value=\"$arr[snavn]\">$arr[snavn]\n";
      }
    ?>
    </select>

    I must have been really tired this morning when I said that they where going to be submitted. I will have that on a page too. But not the first one.

    After some debuggin here..I dinaly manage to change all the variable names right. And now it works like a dream here....


    Thanks a lot kows. You have saved my day. I would never have guessed that I had to echo the whole combo box.


    Thanks ØØ.

Posting Permissions

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



Click Here to Expand Forum to Full Width