Select List Values Retained

Thread Solved

Join Date: Jan 2008
Posts: 19
Reputation: Morty222 is an unknown quantity at this point 
Solved Threads: 0
Morty222 Morty222 is offline Offline
Newbie Poster

Select List Values Retained

 
0
  #1
Feb 12th, 2008
I am using the following query to pull categories from the DB then creating a select list.

Can some tell me how to make the current value selected in the list when they open the category?

<?php
include("mysql.php");
$queryc = "select * from tbl_category WHERE active = 'yes' ORDER by name ASC";
$resultc = mysql_query($queryc);
while ($rowc = mysql_fetch_array($resultc)) {
$catIDc = $rowc['catID'];
$namec = $rowc['name'];
$activec = $rowc['active'];

echo "<option value=$catIDc>$namec</option>";
}
?>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 9
Reputation: monkey56657 is an unknown quantity at this point 
Solved Threads: 1
monkey56657 monkey56657 is offline Offline
Newbie Poster

Re: Select List Values Retained

 
0
  #2
Feb 12th, 2008
I am not quite sure what you are wanting here.

Remember you can only select one item from a drop down by default and since you outputing all that are equal to yes I get confused as to the purpose of the while loop (unless there are many rows...which wouldnt work).

To set the default selected item on a drop down do it like so...

  1. <option value="..." selected="selected"></option>

Could you offer more of an explantion?

-------------------------------------------------------------------

Website Tutorials
Last edited by monkey56657; Feb 12th, 2008 at 7:11 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Select List Values Retained

 
1
  #3
Feb 12th, 2008
  1. <?php
  2. //connection
  3. //select db
  4. $selected_id=$_POST['select'];
  5. $query="Select * from table";
  6. $result=mysql_query($query);
  7. $options="";
  8. while($row=mysql_fetch_array($result)){
  9. $name=$row['name'];
  10. $id=$row['id'];
  11. if($selected_id==$id){
  12. $selected="selected":
  13. }
  14. else {
  15. $selected="";
  16. }
  17. $options.="<option value='$id' $selected>$name</option>";
  18. }
  19. ?>
  20. <html>
  21. <body>
  22. <form method="post" action="test.php">
  23. Select something: <select name="select">
  24. <?php echo $options; ?>
  25. </select><br />
  26. <input type="submit" name="submit" value="submit">
  27. </form>
  28. </body>
  29. </html>

Cheers,
Naveen
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 19
Reputation: Morty222 is an unknown quantity at this point 
Solved Threads: 0
Morty222 Morty222 is offline Offline
Newbie Poster

Re: Select List Values Retained

 
0
  #4
Feb 13th, 2008
Worked great, thanks.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Select List Values Retained

 
0
  #5
Feb 13th, 2008
You are welcome
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC