Page 1 of 1

drop down boxes function result set

Posted: Sat Mar 13, 2010 3:08 pm
by mhill001
Hi,
I am trying to load my drop down boxes from an array returned from a function that generates a result set. Is it possible. Using zend core on ibm i db2 database.

Code: Select all

 
function GetStatus() { 
        
$sql = "SELECT CDDL01 FROM CMSLIBD.TRMCODPF WHERE CDSY = 'BC'
AND CDRT = 'CS'";
 
$stmt =DB2_PREPARE($conn, $sql) or die("db2_prepare failed<br>"); 
 
$result = DB2_EXECUTE($stmt);
     if (!$result){
echo "broken";}
 
        while($row = db2_fetch_assoc($stmt)) 
         { 
              $data = print "{$row[CDDL01]}"; 
              
         } 
      
        return $data; 
 
 }
  
?>
 
<?php
 
include("cms_functions.php");
$status =array();
$status = GetStatus();
.......
 
 
<!Transaction Status> 
            <li id="li_6" >
        <label class="description" for="element_6">Transaction Status </label>
         <?php //createDropdown($status, 'element_6'); ?> 
        <div>
        <select class="element select small" id="element_6" name="element_6"> 
        //  <option value="" selected="selected"></option>
            //<option value="2" >Second option</option>
           // <option value="3" >Third option</option>
            
            
        </select>
        </div><p class="guidelines" id="guide_6"><small>Select Transaction Status</small></p> 
        </li>
 
 

Re: drop down boxes function result set

Posted: Sat Mar 13, 2010 6:16 pm
by McInfo
print() always returns 1. Therefore, $data will always be 1 or NULL, GetStatus() will aways return 1 or NULL, and $status will always become 1 or NULL.

For GetStatus() to return an array, the code around line 15 needs to be changed to

Code: Select all

$data = array();
while ($row = db2_fetch_assoc($stmt)) {
    $data[] = $row['CDDL01'];
}
return $data;
It seems like your question is lacking some details...

Edit: This post was recovered from search engine cache.

Re: drop down boxes function result set

Posted: Sun Mar 14, 2010 12:15 am
by mhill001
I am still learning some concepts - all I want to achieve is
1. call the function
2.Take the results in the result set and put them in my drop down box.

It seems easy but I just cant get the desired results.

Re: drop down boxes function result set

Posted: Sun Mar 14, 2010 1:42 am
by mhill001
I am still learning some concepts - all I want to achieve is
1. call the function
2.Take the results in the result set and put them in my drop down box.

It seems easy but I just cant get the desired results.