Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping array data from database
    text
    copied!<p>I have a little problem with looping odbc_fetch_array in php script... problem is second: I have some data in my DB, and i want to search special data in it... I get data into array throught <code>$row = odbc_fetch_array('$array')</code>, but I am stucked only at last record in this row... So i want to know how to print all data from this array...</p> <p>here is my php code:</p> <pre><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 from 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 = " &lt;table&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Surname&lt;/th&gt; &lt;th&gt;Birth Date&lt;/th&gt; &lt;tr&gt; &lt;td&gt;".$row['f_name']."&lt;/td&gt; &lt;td&gt;".$row['s_name']."&lt;/td&gt; &lt;td&gt;".$birthdate."&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; "; $data['result']['table'] = $table; } </code></pre> <p><strong>EDIT1</strong></p> <p>here is <code>echo</code> inside while</p> <p><code>json_encode(tr)&lt;tr&gt;&lt;td&gt;ALEVTINA &lt;\/td&gt;&lt;td&gt;KARPOVA &lt;\/td&gt;&lt;td&gt;14.07.27&lt;\/td&gt;&lt;\/tr&gt;"null"json_encode(tr)&lt;tr&gt;&lt;td&gt;DACE &lt;\/td&gt;&lt;td&gt;KARPOVA &lt;\/td&gt;&lt;td&gt;08.10.77&lt;\/td&gt;&lt;\/tr&gt;"nullnullnull"json_encode(tr)&lt;tr&gt;&lt;td&gt;OLGA &lt;\/td&gt;&lt;td&gt;KARPOVA</code></p> <p>and here is <code>var_dump</code> outside while</p> <p><code>array(65) { [0]=&gt; string(89) "&lt;tr&gt;&lt;td&gt;GA�INA &lt;/td&gt;&lt;td&gt;KARPOVA &lt;/td&gt;&lt;td&gt;08.03.56&lt;/td&gt;&lt;/tr&gt;"</code></p> <p><strong>EDIT2</strong></p> <p>maybe there is a problem on my html page, where I am getting back this table? here is the code <code>$.ajax ({ data: { action: "search_patient_surname", surname: inserted_surname }, success: function(a) { console.log(a); if (a.errors.length &gt; 0) { //vivodit input_error.val(a.errors.join(' | ')); } $('#Persons').html(a.result.table); } });</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload