php - Looping array data from database -


i have little problem looping odbc_fetch_array in php script... problem second: have data in db, , want search special data in it... data array throught $row = odbc_fetch_array('$array'), stucked @ last record in row... want know how print data array...

here php code:

while ($row = odbc_fetch_array($surnames))                 {                     echo json_encode($row);                      /*$f_name = trim(odbc_result($surnames, "f_name"));                     $s_name = trim(odbc_result($surnames, "s_name"));*/                      //getting birthdate personal id                     $bd = trim(odbc_result($surnames, "pers_kod"));                      $day = substr($bd, 0, 2);                     $month = substr($bd, 2, 2);                     $year = substr($bd, 4, 2);                      $birthdate = $day.".".$month.".".$year;                      $table = "                                 <table>                                     <th>name</th>                                     <th>surname</th>                                     <th>birth date</th>                                      <tr>                                         <td>".$row['f_name']."</td>                                         <td>".$row['s_name']."</td>                                         <td>".$birthdate."</td>                                     </tr>                                 </table>                              ";                      $data['result']['table'] = $table;                 } 

edit1

here echo inside while

json_encode(tr)<tr><td>alevtina <\/td><td>karpova <\/td><td>14.07.27<\/td><\/tr>"null"json_encode(tr)<tr><td>dace <\/td><td>karpova <\/td><td>08.10.77<\/td><\/tr>"nullnullnull"json_encode(tr)<tr><td>olga <\/td><td>karpova

and here var_dump outside while

array(65) { [0]=> string(89) "<tr><td>ga�ina </td><td>karpova </td><td>08.03.56</td></tr>"

edit2

maybe there problem on html page, getting table? here code $.ajax ({ data: { action: "search_patient_surname", surname: inserted_surname }, success: function(a) { console.log(a); if (a.errors.length > 0) { //vivodit input_error.val(a.errors.join(' | ')); } $('#persons').html(a.result.table); } });

the problem $data['result']['table'] getting overwritten on every iteration leaving last record.

also assume want 1 table multiple rows not multiple tables.

try this:

$result_tr = array(); while ($row = odbc_fetch_array($surnames)) {     echo json_encode($row);      /*$f_name = trim(odbc_result($surnames, "f_name"));     $s_name = trim(odbc_result($surnames, "s_name"));*/      //getting birthdate personal id     $bd = trim(odbc_result($surnames, "pers_kod"));      $day = substr($bd, 0, 2);     $month = substr($bd, 2, 2);     $year = substr($bd, 4, 2);      $birthdate = $day.".".$month.".".$year;      $tr = "<tr><td>{$row['f_name']}</td><td>{$row['s_name']}</td><td>{$birthdate}</td></tr>";     $result_tr[] = $tr; }  $table = ""; if (!empty($result_tr)) {     $table = "<table><th>name</th><th>surname</th><th>birth date</th>";     foreach ($result_tr $row) {         $table .= $row;     }     $table .= "</table>"; }  $data['result']['table'] = $table; 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -