Drop Down Default Option

This is a discussion on "Drop Down Default Option" within the PHP Forum section. This forum, and the thread "Drop Down Default Option are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Feb 10th, 2006, 13:37
kal kal is offline
Junior Member
Join Date: Dec 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Drop Down Default Option

Hi

I have coded the following which creates me a database driven drop down menu, however i want to be able have a default option, which is automatically selected based on the value of a varaible.

Any help would be great.

<?php

$query = "select scriptname from script_summary";
$result = mysql_query ($query) or die (mysql_error());
echo "<td><b>Please Select A SCRIPT:</b></td> <td><SELECT name=\"scriptname\">";
if (mysql_num_rows($result)>0)

{
while($row=mysql_fetch_array($result))

{
echo "<option value=\"$row[scriptname]\">$row[scriptname]</option>";
}
}
echo "</SELECT></td>";
?>

Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Feb 11th, 2006, 12:00
Junior Member
Join Date: Feb 2006
Age: 40
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Drop Down Default Option

I use something like the following, changed to replicate your code but not tested.

PHP: Select all

<select name='scriptname'>
        <?php
do {  
?>
        <option value="<?php echo $row['scriptname']?>"<?php if (!(strcmp($row['scriptname'], $_GET['scriptname']))) {echo "SELECTED";} ?>><?php echo $row['scriptname'];?></option>
        <?php
} while ($row mysql_fetch_assoc($result));
  
$rows mysql_num_rows($row);
  if(
$rows 0) {
      
mysql_data_seek($row0);
      
$row mysql_fetch_assoc($results);
  }
?>
</select>
PHP manual gives explanation to strcmp and a quick search on [google]mysql_fetch_array v mysql_fetch_assoc[/google] in google returns some results about it being faster for php4 plus.

Last edited by Rob; Feb 17th, 2006 at 01:05.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Feb 13th, 2006, 07:43
kal kal is offline
Junior Member
Join Date: Dec 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Drop Down Default Option

Cheers mate, i got it working.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
drop, down, default, option

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a default image size using CSS? Inkers Web Page Design 4 Oct 12th, 2007 15:10
example of editing in DataGrid and Default Paging hanusoft ASP.NET Forum 1 Oct 4th, 2007 13:41
Resetting webserver to default !!!!!! EnSComputers Starting Out 3 Apr 23rd, 2007 12:25
How to set default size for html page? mohabitar Web Page Design 5 Mar 11th, 2007 19:12
what is default sqlserver username & password ? clickme_not Databases 1 Aug 27th, 2006 17:57


All times are GMT. The time now is 09:02.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42