Welcome to WebmasterWorld Guest from 54.198.87.238

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Display data from DB - Formatting Issue

     
11:30 am on Aug 19, 2004 (gmt 0)

10+ Year Member



Hi,

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>&nbsp;</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)

11:58 am on Aug 19, 2004 (gmt 0)

10+ Year Member



Two ways of doing it that I can think of

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>

12:00 pm on Aug 19, 2004 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Hi,

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="&nbsp;";
}

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.

12:11 pm on Aug 19, 2004 (gmt 0)

10+ Year Member



Thanks for the response.

Two ways of achieving this, and both look good to me, I'll have a go and I will let you know.

Thanks again.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month