system
September 18, 2010, 8:41am
1
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
system
September 21, 2010, 9:55pm
2
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>
RNEL
September 18, 2010, 11:50am
4
ok thanks… let me know where did you set this
$row_rs_visible['duration_days']
RNEL
September 18, 2010, 9:36am
5
nope… the codes where did you set this $row_rs_experience[‘duration_days’]
RNEL
September 18, 2010, 10:07am
6
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
system
September 18, 2010, 11:41am
7
That just removes all data from the page, so none of the rs_experience data is recovered. (the list doesn’t work either).
RNEL
September 18, 2010, 12:57pm
8
ok. is there any chance you can display your full code here, I guess it’s just on a single page
system
September 18, 2010, 12:49pm
9
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’]
RNEL
September 18, 2010, 12:23pm
10
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
system
September 18, 2010, 9:32am
11
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 ?>
RNEL
September 18, 2010, 9:27am
12
ok. how did you loop through it all?
RNEL
September 18, 2010, 9:22am
13
no not that… the codes before that
system
September 18, 2010, 9:23am
14
I just echoed out $row_rs_experience[‘duration_days’] to make sure and it contains the correct value each time.
system
September 18, 2010, 9:20am
15
$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>
system
September 18, 2010, 9:15am
16
Tried that.
I just get a huge empty list - no values at all?
RNEL
September 18, 2010, 9:18am
17
ok thanks. please show your code related to this
$days=$row_rs_experience['duration_days'];
RNEL
September 18, 2010, 9:03am
18
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”
system
September 18, 2010, 12:10pm
20
$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);