|
-
May 7th, 2004, 03:22 PM
#1
Thread Starter
Frenzied Member
switch
Hi have this code working on my site but I want it to detect and switch from a sql query.. can this be done?
PHP Code:
<select name="club_id">
<?php
switch ($club_id)
{
case "2":
$opt2 = " selected ";
break;
case "3":
$opt3 = " selected ";
break;
case "4":
$opt4 = " selected ";
break;
case "5":
$opt5 = " selected ";
break;
case "6":
$opt6 = " selected ";
break;
case "8":
$opt8 = " selected ";
break;
case "9":
$opt9 = " selected ";
break;
}
?>
<option <?php echo $opt2; ?> value="2">Auckland</option>
</select>
-
May 8th, 2004, 01:25 PM
#2
Can you possibly explain a little more. I don't really understand what you mean.
-
May 8th, 2004, 01:53 PM
#3
Thread Starter
Frenzied Member
Originally posted by visualAd
Can you possibly explain a little more. I don't really understand what you mean.
sure, I the code I posted does a query from the sql database and switches the drop down box!!
However I have added all the option by hand, I want it to do this for all options on my table... would a loop work?
-
May 8th, 2004, 02:31 PM
#4
The usual way is
PHP Code:
for($i = 0; $i < count($options); ++i) {
echo "<option value=\"$i\"".($club_id == $i ? ' selected="selected"' : '').
'>'.$options[$i]."</option>\n";
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|