| PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >> |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread |
|
|
#1 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
9 posts
Gave thanks: 0
Thanked 0 times
|
Make drop down menu list automaticly selected in php?
I’m having a story script where author has to select the character in the list. How do I make the list selected on a certain character even before the author does anything?
Here’s part of the script: $result = mysql_query("SELECT gid, genre FROM ".$tableprefix."fanfiction_genres"); $numgenres = mysql_num_rows($result); $output .= "<INPUT type=\"hidden\" name=\"numgenres\" value=\"$numgenres\">"; if($numgenres != "0") { if($gid == "") $output .= "<font style=\"color:red\">"; $output .= ""._GENRES.":"; if($gid == "") $output .= "</font>"; $output .= "</td><td>"; $output .= "<select name=\"gid[]\" size=\"5\" multiple>"; while ($genreresults = mysql_fetch_array($result)) { $output .= "<option value=\"$genreresults[genre]\""; if($gid != "") { if(in_array($genreresults[genre], $gid)) $output .= " selected"; } $output .= ">$genreresults[genre]</option>"; } } $output .= " </td><td>"._GENREINFO." Do you need the whole script? I know nothing about php. I tried to add the <option selected>character’s name</option> but it didn’t really work because I don’t know where to add it nor is it the right code. |
|
|
|
|
|
#2 (permalink) |
|
Surpass Fan
Super #1
Joined in Dec 2003
Lives in NJ
5,057 posts
Gave thanks: 0
Thanked 4 times
|
while you're using PHP to generate HTML - what you're really asking is how to make an option appear selected.
do you have a link to the page that is built by this code? it would make it a little easier to work backwards. |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
9 posts
Gave thanks: 0
Thanked 0 times
|
my site isn't done yet but I know this site use the same script. http://www.fictionised.net/
You want to see the page that use this code? You have to log in and click on the add new story link. You can use my account. user=aly pass=fictionised |
|
|
|
|
|
#4 (permalink) |
|
minor deity
Super #1
Joined in Apr 2004
Lives in Georgia
Hosted on XEON
7,332 posts
Gave thanks: 23
Thanked 93 times
|
You just need to add the word 'selected' to the one you want listed - like this:
Code:
<option selected>3</option> Code:
while ($genreresults = mysql_fetch_array($result))
{
$output .= "<option value=\"$genreresults[genre]\"";
if($gid != "")
John
__________________
Proud to be a Surmunity Mod! XEON Make a fundamental difference! My Sites: Curious about Brewing Beer? Join the community! >>>>> Some Change is GOOD! Keep your paycheck! Support the Fair Tax Get into an Art museum Victorian London It's your brain -ON WEB - mybrainhost.com (under development) What SHOULD Government do? Much Less than it Does! |
|
|
|
|
|
#6 (permalink) |
|
Registered User
Fresh Surpasser
Joined in Aug 2004
9 posts
Gave thanks: 0
Thanked 0 times
|
It selected the whole list. How do I make it select only one thing in the list? Also how do I hide the list? I tried type=\"hidden\" but it didn't work.
Last edited by Lyssa; September 13th, 2004 at 4:23 PM. Reason: Add another question. |
|
|
|