Results 1 to 2 of 2

Thread: drop down value from mysql problem

  1. #1
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question drop down value from mysql problem

    Hi

    First of all sorry for my English

    I'm new here and Im a php coding newbie..i'm currently testing

    doing a simple program for xoops cms...

    i'm having trouble with this can anyone help me

    ok i have this



    two table

    info_unit : log_id, occupation
    myocc : id, occ_list


    input

    PHP Code:

    <select name='occupation'>
     <option value="">Sellect Occupation</option>
       <?php
     
    global $xoopsDB
     
    $result mysql_query("SELECT * FROM ".$xoopsDB->prefix("myocc")."");
     
     while(
    $row mysql_fetch_array($result))
    {
    $occ_list=$row['occ_list'];
    $occupation=$occ_list;
    echo 
    "<option value='$occupation'>$occ_list</option>";
    }
    ?>


    </select>
    the above code working properly...the drop down will display value from myocc..

    and the value is submitted to info_unit table successfully

    the problem is this code below when i want to edit a record in the edit form
    the value that i selected in the input form is not selected



    update record

    PHP Code:

    <?php
    $log_id
    =$_POST[log_id];

    if(
    $log_id=='')
    {
    echo 
    "<center>Please Select a record</center><br /><br />";
    }

    else 
    {
    $result mysql_query("SELECT * FROM info_unit WHERE log_id=$log_id");
    while(
    $row mysql_fetch_array($result))
    {
    $log_id=$row['log_id'];
    $occupation=$row['occupation'];
    }
    ?>
    <select name='occupation'>
    <option value=''>Select occupation</option>
     
    <?php
     
      
    global $xoopsDB
      
    $result mysql_query("SELECT * FROM ".$xoopsDB->prefix("myocc")."");

     while(
    $row mysql_fetch_array($result))
    {
    $occ_list=$row['occ_list'];
     
            if(
    $occupation == '$occ_list') {
        
        echo 
    "<option value='$occupation' selected>$occ_list</option>";
    }
     
    else
    {   

    echo 
    "<option value='$occupation'>$occ_list</option>";
    }  

    }
    ?>

      </select>

  2. #2
    Join Date
    Jan 2010
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ok nevermind i solved this

    i just changed the if statement and sql query

    PHP Code:

    <?php
    $log_id
    =$_POST[log_id];

    if(
    $log_id=='')
    {
    echo 
    "<center>Please Select a record</center><br /><br />";
    }

    else 
    {
    $result mysql_query("SELECT * FROM info_unit WHERE log_id=$log_id");
    while(
    $row mysql_fetch_array($result))
    {
    $log_id=$row['log_id'];
    $occupation=$row['occupation'];
    }
    ?>
    <select name='occupation'>
    <option value=''>Select occupation</option>
     
    <?php
     
      
    global $xoopsDB
      
    $result mysql_query("SELECT * FROM ".$xoopsDB->prefix("myocc").",".$xoopsDB->prefix("infounit")." WHERE log_id=$log_id");

     while(
    $row mysql_fetch_array($result))
    {
    $occ_list=$row['occ_list'];
    $occupation=$row['occupation'];
     
            if(
    $occ_list == $occupation) {
        
        echo 
    "<option value='$occupation' selected>$occ_list</option>";
    }
     
    else
    {   
    $occupation=$occ_list;
    echo 
    "<option value='$occupation'>$occ_list</option>";
    }  

    }
    ?>

      </select>
    Last edited by sarahmx; 01-10-2010 at 01:34 AM.

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
  •