data is not fetching into the combo box while generating html controls dynamically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shruti12
    New Member
    • Apr 2017
    • 2

    data is not fetching into the combo box while generating html controls dynamically

    Code:
    <?php
    include("con_gen.php");
    
    error_reporting(E_ALL);
    
    // DATABASE CONNECTION AND SELECTION VARIABLES - GET THESE FROM YOUR HOSTING COMPANY
    $db_host = "localhost"; // PROBABLY THIS IS OK
    $db_name = "idcard";
    $db_user = "root";
    $db_word = "";
    
    // OPEN A CONNECTION TO THE DATA BASE SERVER AND SELECT THE DB
    $mysqli = new mysqli($db_host, $db_user, $db_word, $db_name);
    
    // DID THE CONNECT/SELECT WORK OR FAIL?
    if ($mysqli->connect_errno)
    {
        $err
        = "CONNECT FAIL: "
        . $mysqli->connect_errno
        . ' '
        . $mysqli->connect_error
        ;
        trigger_error($err, E_USER_ERROR);
    }
    
    // RUN A QUERY
    $result = mysqli_query($mysqli,"SELECT value FROM combo1");
    $num_rows = mysqli_num_rows($result);
    
    //echo "$num_rows Rows\n";
    if ($result->num_rows > 0) {
         // output data of each row
      $array = Array();
      $array1 = Array();
         while($row = $result->fetch_assoc()) {
             //echo "<br> value: ". $row['value'].  "<br>";
              $array[] = $row['value'];
            
    }
    //print_r($array);
    
    $sql = "SELECT static_name FROM static_values";
    $result = mysqli_query($mysqli, $sql);
    if ($result && mysqli_num_rows($result) > 0) 
     while($row = mysqli_fetch_array($result)){
                    //echo "<option>" . $row['static_name'] . "</option>";
                    $array1[]=$row['static_name'];
                     
                     //echo $source;
                   }
                  // print_r($array1);
                   foreach ($array as $row)
    {
      if(in_array($row, $array1))
      {
    $sql = "SELECT source_table,Alias_name FROM static_values where static_name='$row'";
    $res = $mysqli->query($sql);
    
    // DID THE QUERY WORK OR FAIL?
    if (!$res)
    {
        $err
        = 'QUERY FAILURE:'
        . ' ERRNO: '
        . $mysqli->errno
        . ' ERROR: '
        . $mysqli->error
        . ' QUERY: '
        . $sql
        ;
        trigger_error($err, E_USER_ERROR);
    }
    
    // ARE THERE ANY ROWS IN THE RESULTS SET
    
    if ($res->num_rows == 0)
    {
        trigger_error("ERROR: NO DATA FOUND BY $sql", E_USER_ERROR);
    }
    
    // RETRIEVE THE ROWS INTO AN ARRAY OF HTML STATEMENTS
    $html = "";
    //$html=$html.'<form method="POST" action="">';
    
    while ($row = $res->fetch_object())
    {
        $html =$html.' 
    <tr>
      <td>
        <div class="row-fluid">
    
          <div class="span3 bgcolor">
         <label>'.$row->Alias_name.'</label>
    
    
            <select  id='.$row->source_table.' name='.$row->source_table.' data-live-search="true" class="selectpicker form-control">
                 
                   <?php foreach ( $Data->'.$row->source_table.' as $key =>$item)  echo "<option value=".$key.">".$item."</option>" ;?>
                
              </select> 
                                              </div>
          </div>
      </td>
    </tr>';
    
    }
    }
    
    else
    {
        $html =$html.' 
    <tr>
      <td>
       <div class="row-fluid">
                   
                <div class="span3 bgcolor">
                <label>'.$row.'</label>
    
                     <input id='.$row.' type="text" placeholder=" Enter Value " name='.$row.' style="width:100%" class="form-control" />
                                  
                    </select> 
    </div>
    </div>
      </td>
    </tr>';
    
    }
    }
    $html=$html.'<input type="submit" value="SUBMIT" class="btn btn-success"  name="submit" />';
    // COLLAPSE THE ARRAY INTO A STRING AND SHOW THE WORK PRODUCT
    //$doc = implode(PHP_EOL,$html);
    
    echo htmlentities($html);
    echo $html;
    
    }
    
    ?>
    here we have generating html tags dynamically and also generating actual controls of those tags , when executing ,the dynamically generated html tags in another php page it is working fine and fetching data into the select boxes but generating actual controls on that page itself it is generating actual controls but data is not fetching into the select boxes it is showing the word ".item." into the select box but it's not actual data
Working...