SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    assuming you fetched $days correctly

    Code:
    <option value="<?php echo $i;?>" selected="selected"><?php echo 
    $days[$i]; ?>
    notice [$i] and why this exists on all options? selected="selected"

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried that.
    I just get a huge empty list - no values at all?

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks. please show your code related to this

    PHP Code:
    $days=$row_rs_experience['duration_days']; 

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $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>

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no not that... the codes before that

  7. #7
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just echoed out $row_rs_experience['duration_days'] to make sure and it contains the correct value each time.

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. how did you loop through it all?

  9. #9
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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 ?>

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope... the codes where did you set this $row_rs_experience['duration_days']

  11. #11
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $colname_rs_experience = "-1";
    if (isset($_GET['id'])) {
    $colname_rs_experience = $_GET['id'];
    }
    mysql_select_db($database_con_onedatabase, $con_onedatabase);
    $query_rs_experience = sprintf("SELECT * FROM experience WHERE id = &#37;s", GetSQLValueString($colname_rs_experience, "int"));
    $rs_experience = mysql_query($query_rs_experience, $con_onedatabase) or die(mysql_error());
    $row_rs_experience = mysql_fetch_assoc($rs_experience);
    $totalRows_rs_experience = mysql_num_rows($rs_experience);

  12. #12
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace
    PHP Code:
    $row_rs_experience mysql_fetch_assoc($rs_experience); 
    with
    PHP Code:
    while ($row_rs_experience mysql_fetch_assoc($rs_experience)) {
    $days[] = $row_rs_experience['duration_days'];

    also, free your result

  13. #13
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That just removes all data from the page, so none of the rs_experience data is recovered. (the list doesn't work either).

  14. #14
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks... let me know where did you set this

    PHP Code:
    $row_rs_visible['duration_days'

  15. #15
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $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 = &#37;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);

  16. #16
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    PHP Code:
    if ($row_rs_visible['duration_days']==1) {


    like this
    PHP Code:
    //if ($row_rs_visible['duration_days']==1) {

    //} 
    then we'll see what to do next

  17. #17
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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']

  18. #18
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok. is there any chance you can display your full code here, I guess it's just on a single page

  19. #19
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can I PM you with it?

  20. #20
    SitePoint Zealot
    Join Date
    Jul 2010
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah sure, thanks

  21. #21
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    106
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •