icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » Make drop down menu list automaticly selected in php?

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old September 12th, 2004, 9:29 AM   #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.
Lyssa is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 12th, 2004, 9:47 AM   #2 (permalink)
sam
Surpass Fan
Super #1
 
sam's Avatar
 
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.
sam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 12th, 2004, 10:26 AM   #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
Lyssa is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 12th, 2004, 12:12 PM   #4 (permalink)
minor deity
Super #1
 
Bigjohn's Avatar
 
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>
so you have to figure out how to do the 'selected' test inside this loop:
Code:
 while ($genreresults = mysql_fetch_array($result))

{

$output .= "<option value=\"$genreresults[genre]\"";

if($gid != "")
because you have to make $output .="<option selected value=

John
__________________
Proud to be a Surmunity Mod!
XEON PASS60 PASS61
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!
Bigjohn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 12th, 2004, 5:39 PM   #5 (permalink)
Registered User
Seasoned Poster
 
Scribe's Avatar
 
Joined in Aug 2004
84 posts
Gave thanks: 0
Thanked 0 times
aye, big john is right
Scribe is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 13th, 2004, 4:17 PM   #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.
Lyssa is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On