Forum Moderators: coopster
I have a code below:
<table width="97%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td valign="top" colspan="2">
<?php
$result = mysql_query("SELECT * FROM man_info where id=$id");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }
while ( $row = mysql_fetch_array($result) ) {
echo("<H1>" . $row["firstname"] . " " . $row["middlename"] . " " . $row["lastname"] . "</H1>");
}
?>
</td>
</tr>
<tr>
<td width="43%" valign="top" bgcolor="#FFFFCC">
<p><span class="highlite">Region:</span> <br>
<span class="highlite">Province:</span> <br>
<span class="highlite">District:</span> <b> </b><br>
<span class="highlite">Municipality:</span> </p>
</td>
<td width="57%" valign="top" bgcolor="#FFFFCC">
<?php
$result = mysql_query("SELECT * FROM man_info where id=$id");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }
while ( $row = mysql_fetch_array($result) ) {
echo("<p> <b>" . $row["region"] . "</b><br>");
echo("<b>" . $row["province"] . "</b><br>");
echo("<b>" . $row["district"] . "</b><br>");
echo("<b>" . $row["municipality"] . "</b></p>");
}
?>
</td>
</tr>
<tr bgcolor="#FFCC99">
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="43%" class="highlite">
<p class="highlite">Party:</p>
</td>
<td valign="top" width="57%">
<?php
$result = mysql_query("SELECT * FROM man_info where id=$id");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }
while ( $row = mysql_fetch_array($result) ) {
echo("<p> <b>" . $row["party"] . "</b></p>");
}
?>
</td>
</tr>
<tr>
If you had noticed, I used the same set of commands twice already:
$result = mysql_query("SELECT * FROM man_info where id=$id");
if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }
This is working already but I'm just wondering if there a better way of writing this? Probably just use PHP codes for tables (How do I do that anyway?) or some kind of global variable?
Thanks a lot for the help.
<?php
$result = mysql_query("SELECT * FROM man_info where id=$id");if (!$result) {
echo("<P>Error performing query: " . mysql_error() . "</P>");
exit(); }while ( $row = mysql_fetch_array($result) ) {
echo("<H1>" . $row["firstname"] . " " . $row["middlename"] . " " . $row["lastname"] . "</ H1>");
?>
</td>
</tr>
<tr>
<td width="43%" valign="top" bgcolor="#FFFFCC">
<p><span class="highlite">Region:</span> <br>
<span class="highlite">Province:</span> <br>
<span class="highlite">District:</span> <b> </b><br>
<span class="highlite">Municipality:</span> </p>
</td>
<td width="57%" valign="top" bgcolor="#FFFFCC"><?php
echo("<p> <b>" . $row["region"] . "</b><br>");
echo("<b>" . $row["province"] . "</b><br>");
echo("<b>" . $row["district"] . "</b><br>");
echo("<b>" . $row["municipality"] . "</b></p>");?>
</td>
</tr>
<tr bgcolor="#FFCC99">
<td colspan="2">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="43%" class="highlite">
<p class="highlite">Party:</p>
</td>
<td valign="top" width="57%"><?php
echo("<p> <b>" . $row["party"] . "</b></p>");
} //end of loop
?>
</td>
</tr>
<tr>
[edited by: Birdman at 8:54 pm (utc) on April 2, 2003]
$counter = 0;
while ( $row = mysql_fetch_array($result) ) {
$man_infoarr[$counter] = array($row["region"],$row["province"],$row["district"],$row["municipality"]);
echo("<p> <b>" . $row["region"] . "</b><br>");
echo("<b>" . $row["province"] . "</b><br>");
echo("<b>" . $row["district"] . "</b><br>");
echo("<b>" . $row["municipality"] . "</b></p>");
$counter++;
}
then farther down you can just iterate through your array.