Jump to content

[SOLVED] Trying to create drop down lists...


Timb75

Recommended Posts

that are populated using the database. I receive this error:

No database selected
SELECT Name FROM Teams

 

Name is a field inside the Teams table if this helps.

 

Here is the code I am using:

 

<?php 
$user = "";  
$host = ""; 
$password = ""; 
$dbName = "olevetpo_polls"; 

/* make connection to database */  
mysql_connect($host, $user, $password) OR DIE( "Unable to connect 
to database"); 
mysql_select_db($dbName); //did you forget this line? 

$sql = "SELECT Name FROM Teams"; 
$query = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT 
?> 

<form action="action" method="post">  
<select name="option">  

<?php  
while ($row = mysql_fetch_array($result)) {  
    echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n";  
}  
?>  
</select>  
<input type="submit">  
</form>

 

I left the database name, but not the rest for obvious reasons.

 

First, I am a big time noob when it comes to php, I found this code here at phpfreaks. I do know that this only shows one drop list....

 

With that said, I need some other help too....

 

I am trying to create a college football human poll, so I need 24 more of these drop downs (stacked on top of each other and with #1, #2, #3, etc preceeding the dropdowns), but only one submit, after the final list.

 

How would I do this?

 

 

Link to comment
Share on other sites

this might help I was trying to make labels and checkboxes in a similar way

 

<?php

$labels = array(
            0 => '200mm x 200mm',
            1 => '200mm x 300mm',
            2 => '200mm x 400mm',
            3 => '200mm x 500mm',
            4 => '200mm x 600mm',
        );

foreach ($labels as $named1 => $label) {
    print '<label>' .$label. '</label><input id="sizes" name="sizes[' .$named1. ']" type="checkbox" value="' . $label. '" onclick="setChecks(this)"';
    //if ($key == 0){
 // print "checked";
 //}
    print ' /><input id="price" name="price[' .$named1. ']" type="text" class="dropdown" /><br/>';
}
?>

 

 

Link to comment
Share on other sites

do you get any errors if you change this:

mysql_select_db($dbName); //did you forget this line? 

to

mysql_select_db($dbName) or die(mysql_error());

 

That works....thanks.

 

Now for my nex question:

 

What do I need to do to create more than 1 drop down list that are stacked in different rows?

 

How would I create the table to do so? I know HTML, the PHP is what is kicking my butt.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.