Set initial value of dynamic list

I have a menu list on an update record page that I am trying to pre populate with the number in that database field. I’d like to make the initial value equal to $row_rs_experience[‘duration_days’]

This is the list menu code I have at present


<?php $days=$row_rs_experience[‘duration_days’]; ?>

<select name=“duration_days” class=“formrightcolumnskinny” id=“duration_days”>
<?php
for( $i=0; $i<=365; $i++ )
{?>
<option value=“<?php echo$i;?>” selected=“selected”><?php echo $days;?>

<?php ;} ?>
</option>


That’s the closest I’ve got. It does select the right value, which is great but when I open up the menu I just get a list only containing that same value - 365 times. Anyone know where I am going wrong?

Cheers

Dave

Thanks RNEL
That worked perfectly.

For anyone else who’s interested, here’s the solution RNEL came up with:

<select name=“duration_hours” class=“formrightcolumnskinny” id=“duration_hours”>
<?php for( $i=0; $i<=23; $i++ ){ ?>
<option value=“<?php echo $i; ?>”<?php echo ($days==$i ? ’ selected=“selected”’ : ‘’); ?>>
<?php echo $i; ?>
</option>
<?php } ?>
</select>

yeah sure, thanks

ok thanks… let me know where did you set this


$row_rs_visible['duration_days']

nope… the codes where did you set this $row_rs_experience[‘duration_days’]

replace


$row_rs_experience = mysql_fetch_assoc($rs_experience);

with


while ($row_rs_experience = mysql_fetch_assoc($rs_experience)) {
$days[] = $row_rs_experience['duration_days'];
}

also, free your result

That just removes all data from the page, so none of the rs_experience data is recovered. (the list doesn’t work either).

ok. is there any chance you can display your full code here, I guess it’s just on a single page

It’s okay, that bit does work
$row_rs_visible[‘duration_days’] is equal to 1 if it isn’t equal to 1 the whole menu item is not displayed.

In this instance $row_rs_visible[‘duration_days’] is equal to 1 so the menu item is displayed and it works perfectly but I just can’t get it to display set to the value rs_experience[‘duration_days’]

It doesn’t display anything because $row_rs_visible[‘duration_days’] is not equal to 1. Try this, let’s just see if there’s any values that will be returned.

find and make this condition


if ($row_rs_visible['duration_days']==1) {

}

like this


//if ($row_rs_visible['duration_days']==1) {

//}

then we’ll see what to do next

Crikey - not sure what you mean. Here’s the entire chunk that deals with that bit. Does this help?

<?php // SHOW/HIDE duration_days
if ($row_rs_visible[‘duration_days’]==1) {
// set variable $days to pre-populate drop down menu with initial value
$days=$row_rs_experience[‘duration_days’];
?>
<div class=“formleftcolumnnarrow”><?php echo $row_rs_input_titles[‘duration_days’]; ?>:</div>
<div class=“formrightcolumnskinny”>
<select name=“duration_days” class=“formrightcolumnskinny” id=“duration_days”>
<?php
for($i=0; $i<=365; $i++ )
{?>
<option value=“<?php echo $i;?>” selected=“selected”><?php echo $days[$i]; ?>

<?php ;} ?>
</option>
</select>
</div>
<?php }
// SHOW/HIDE duration_days CODE ENDS ?>

ok. how did you loop through it all?

no not that… the codes before that

I just echoed out $row_rs_experience[‘duration_days’] to make sure and it contains the correct value each time.

$days=$row_rs_experience[‘duration_days’];
?>
<div class=“formleftcolumnnarrow”><?php echo $row_rs_input_titles[‘duration_days’]; ?>:</div>
<div class=“formrightcolumnskinny”>
<select name=“duration_days” class=“formrightcolumnskinny” id=“duration_days”>
<?php
for($i=0; $i<=365; $i++ )
{?>
<option value=“<?php echo $i;?>” selected=“selected”><?php echo $days[$i]; ?>

<?php ;} ?>
</option>
</select>

Tried that.
I just get a huge empty list - no values at all?

ok thanks. please show your code related to this


$days=$row_rs_experience['duration_days'];

assuming you fetched $days correctly


<option value="<?php echo $i;?>" selected="selected"><?php echo 
$days[$i]; ?>

notice [$i] and why this exists on all options? selected=“selected”

Can I PM you with it?

$colname_rs_visible = “-1”;
if (isset($category)) {
$colname_rs_visible = $category;
}
mysql_select_db($database_con_onedatabase, $con_onedatabase);
$query_rs_visible = sprintf(“SELECT * FROM input_titles_visible WHERE category = %s”, GetSQLValueString($colname_rs_visible, “text”));
$rs_visible = mysql_query($query_rs_visible, $con_onedatabase) or die(mysql_error());
$row_rs_visible = mysql_fetch_assoc($rs_visible);
$totalRows_rs_visible = mysql_num_rows($rs_visible);