SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display id and name in dropdown list using defined function

    how can i use function below to populate selected data into dropdown list?

    PHP Code:
    function loadDiseaseCategory($dcid)
    {        
            global 
    $ecisDB$parent;
            
    $parent 0;
            
    $sql "SELECT diseaseCategoryId, diseaseCategoryName 
                  FROM DiseaseCategory 
                      WHERE diseaseCategoryClass = '
    $dcid
                      AND diseaseCategoryParent = '
    $parent
                  ORDER BY diseaseCategoryName"
    ;
            
    $query $ecisDB->query($sql) or die(mysql_error());
            
    $result $ecisDB->fetch_array($query);
            return 
    $result;
    }

    # dropdown list

    <select name="dis_cat" id="dis_cat" onChange="this.form.submit();">
    <
    option selected>Select</option>
    </
    select

  2. #2
    SitePoint Zealot oivaf's Avatar
    Join Date
    Apr 2003
    Location
    Mexico
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simple, you cannot use it.

    You have to add that code which could be something similar to:
    PHP Code:
    //Assuming the $result var is an array with the form
    array ( => array ( diseaseCategoryIddiseaseCategoryName))

    //not working code just illustrative
    foreach ($result as $category) {
          echo 
    '<option  value="'$category[0] .'">'$category[1] .'</option>';

    Do make a print_r of $result and show the output.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What have you got so far? Post your code.

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2005
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not solve yet. i have done many ways but the best thing is, the ids and names appear in the list. suppose no like that right. actually, i want to change this style of code (below) by creating a function to execute the sql process.

    PHP Code:
    <select name="dis_cat" id="dis_cat" onChange="this.form.submit();">
    <option selected>Select</option>
    <?php             
        
    global $ecisDB$parent;
        
    $parent 0;
        
    $sql "SELECT diseaseCategoryId, diseaseCategoryName 
            FROM DiseaseCategory 
            WHERE diseaseCategoryClass = '
    $dcid
            AND diseaseCategoryParent = '
    $parent
            ORDER BY diseaseCategoryName"
    ;
            
    $query $ecisDB->query($sql) or die(mysql_error());
            while(
    $result $ecisDB->fetch_array($query)){
                if(
    $result['diseaseCategoryId'] == $discatid){
    ?>

    <option value="<?php echo $result['diseaseCategoryId']; ?>" selected><?php echo $result['diseaseCategoryName']; ?></option>
    <?php } else { ?>
    <option value="<?php echo $result['diseaseCategoryId']; ?>"><?php echo $result['diseaseCategoryName']; ?></option>
    <?php } } ?>
    </select>
    this is my latest code while playing with array(). i tried to print_r the $result from the function.

    PHP Code:
    <?php print_r($ecisDiseaseCategory->loadDiseaseCategory($dcid)); ?>
    output:

    Array ( [0] => 1 [diseaseCategoryId] => 1 [1] => Acute upper respiratory infections [diseaseCategoryName] => Acute upper respiratory infections )


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
  •