I have this table "city" in my database:
|id |id_city_a |id_city_b|distance| |1 |1 | 1 | 0 | |2 |1 | 2 | 8 | |3 |1 | 3 | 6 | |4 |2 | 1 | 8 | |5 |2 | 2 | 0 | |6 |2 | 3 | 9 | |7 |3 | 1 | 6 | |8 |3 | 2 | 9 | |9 |3 | 3 | 0 |
I want the end result to be in a matrix, such as:
| | 1 | 2 | 3 | | 1 | 0 | 8 | 6 | | 2 | 8 | 0 | 9 | | 3 | 6 | 9 | 0 |
This is my code :
function random() { include('config/koneksi.php'); $result = mysql_query("select * from temp_hasil"); $n =mysql_num_rows(mysql_query("SELECT * FROM temp_hasil")); for ($i = 1; $i <= $n; $i++) { for ($j = 1; $j <= $n; $j++) { $rows = mysql_fetch_array($result); $this->table[$i][$j] = $i == $j ? INF : $rows['id']; } } } function __toString() { $str = '<table class="table table-bordered" id="tableInput"> <tbody>'; $str .= '<tr><td></td>'; foreach ($this->table as $rowName => $row) { $str .= "<td>$rowName</td>"; } $str .= '</tr>'; foreach ($this->table as $rowName => $row) { $str .= "<tr><td>$rowName</td>"; foreach ($row as $columnName => $value) { $str .= "<td>"; $str .= '<input class="form-control" type="text" value="' . $value . '" name="table[' . $rowName . '][' . $columnName . ']" requied' . ($columnName == $rowName ? ' disabled' : '') . '>'; $str .= "</td>"; } $str .= '</tr>'; } $str .= '</tbody></table>'; return $str; } } $str .= '</tr>'; foreach ($this->table as $rowName => $row) { $str .= "<tr><td>$rowName</td>"; foreach ($row as $columnName => $value) { $str .= "<td>"; $str .= '<input class="form-control" type="text" value="' . $value . '" name="table[' . $rowName . '][' . $columnName . ']" requied' . ($columnName == $rowName ? ' disabled' : '') . '>'; $str .= "</td>"; } $str .= '</tr>'; } $str .= '</tbody></table>'; return $str; }
`
How do I code it in php? please help me.