dynamic options

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

dynamic options

Post by aravona »

I've a series of options (chosen with a radio button) which draw data from my database, I want to make the first option automatically chosen.

Right now I can only get it to auto-choose the last option.

The problem I'm having is there is no set value as it chooses it from the DB and theres a number of options that this could be so I don't know how to go about forcing it to the first one.

Code: Select all

<?php while (wpsc_have_variation_groups()) : wpsc_the_variation_group(); ?>
<input type="radio"  value="<?php echo wpsc_the_variation_id(); ?>" class='wpsc_select_variation' name="variation[<?php echo wpsc_vargrp_id(); ?>]" id="<?php echo wpsc_vargrp_form_id(); ?>" checked="checked">
<?php endwhile; ?>
The above code is what generates the radio buttons, any ideas how to make this choose the first option?

Cheers,

Aravona
maneetpuri
Forum Commoner
Posts: 60
Joined: Tue Oct 07, 2008 6:32 am

Re: dynamic options

Post by maneetpuri »

Hi,

Define a variable set to zero and in the loop check if the value is zero then add the checked attribute and make the value of this variable 1 and this will make the first radio button selected by default.

Cheers,

~Maneet
Post Reply