Forum Moderators: coopster
I've got this problem with displaying data from a DB, but with using <TD> within a table.
What I am trying to do is that I have a list of suppliers in a DB, and what I have a 2 column table, see below, but the problem I am having is trying to list the suppliers without repeating the word 'supplier' in a <TD>. Hope that makes sense.
This is what I'm trying to achieve see the following code:-
<table>
<tr>
<td>Supplier</td>
<td>Name of Supplier goes here from DB</td>
</tr>
<tr>
<td> </td>
<td>Name of Supplier goes here from DB</td>
</tr>
</table>
I know the PHP code to display the data from a DB thats very simple, but its just finding the logic to do it.
Many Thanks
W :o)
Get the number of results from the db query and then do something like
<table>
<tr>
<td rowspan="number of results" valign="top">Supplier</td>
<td>Name of Supplier goes here from DB</td>
</tr>
<tr>
<td>Name of Supplier goes here from DB</td>
</tr>
</table>
or
<table>
<tr>
<td valign="top">Supplier</td>
<td>Name of Supplier goes here from DB<br>
Name of Supplier goes here from DB<br>
Name of Supplier goes here from DB
</td>
</tr>
</table>
What you can do is assign a variable that holds the value of "Supplier" and then when you use a while loop to pull your data, only display the value of the variable for the first row.
Something like:
$variable = "Supplier";
<table>
while ($row = mysql_fetch_array($result))
{if ($row['id']=="1")
{
$string = $variable;
}
else
{
$string=" ";
}echo "<tr>\n";
echo "<td>" . $string . "</td>\n";
echo "<td>Name of Supplier goes here from DB</td>\n";
echo "</tr>\n";
}
Maybe not the best way, but it should work ok.