I am using following code to show in a table database results:
<table cellspacing="0" width="700">
<tbody>
<?php
$sql = "SELECT id1, id2, id3, id4, id5 FROM table";
$result = pg_query($db, $sql);
if (pg_num_rows($result) != 0)
{
while($results_row = pg_fetch_row($result))
{
echo '
<tr>
<td id="id1"> '.$results_row[1].' </td>
<td id="id2"> '.$results_row[2].' </td>
<td id="id3"> '.$results_row[3].' </td>
<td id="id4"> '.$results_row[4].' </td>
<td id="id5"> ' if (.$results_row[5]. != "")
{'.$results_row[5].'}' </td>
</tr>
';
}
}
?>
</tbody>
</table>
Obviously I'm having problems with "if" statement so nothing appears on the screen... Also I'd like to ask why dots are used in both sides of $results_row. Is it because it's an array?
One possible solution:
echo '
<tr>
<td id="id1"> '.$results_row[1].' </td>
<td id="id2"> '.$results_row[2].' </td>
<td id="id3"> '.$results_row[3].' </td>
<td id="id4"> '.$results_row[4].' </td>
<td id="id5"> ';
if($results_row[5] != "") { echo $results_row[5]; }
echo '
</td>
</tr>';
0 comments:
Post a Comment