| | |
Select List Values Retained
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 19
Reputation:
Solved Threads: 0
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>";
}
?>
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>";
}
?>
•
•
Join Date: Feb 2008
Posts: 9
Reputation:
Solved Threads: 1
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...
Could you offer more of an explantion?
-------------------------------------------------------------------
Website Tutorials
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...
PHP Syntax (Toggle Plain Text)
<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.
php Syntax (Toggle Plain Text)
<?php //connection //select db $selected_id=$_POST['select']; $query="Select * from table"; $result=mysql_query($query); $options=""; while($row=mysql_fetch_array($result)){ $name=$row['name']; $id=$row['id']; if($selected_id==$id){ $selected="selected": } else { $selected=""; } $options.="<option value='$id' $selected>$name</option>"; } ?> <html> <body> <form method="post" action="test.php"> Select something: <select name="select"> <?php echo $options; ?> </select><br /> <input type="submit" name="submit" value="submit"> </form> </body> </html>
Cheers,
Naveen
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Continue? (PHP)
- Source Code that don't work? (Java)
Other Threads in the PHP Forum
- Previous Thread: Online Reservation of Books
- Next Thread: How to create a web page?
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary bounce broken cakephp checkbox class cms code codingproblem combobox cron curl database date display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla js limit link login loop mail menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion regex remote return script search server sessions smash sms soap source space sql syntax system table tutorial up-to-date update upload url validation validator variable video web webapplications websitecontactform xml youtube






