Welcome to WebmasterWorld Guest from 23.20.193.33

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)

Full Member

10+ Year Member

joined:Feb 13, 2003
posts:220
votes: 0


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)

Junior Member

10+ Year Member

joined:Jan 9, 2003
posts:180
votes: 0


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)

Senior Member

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

joined:Mar 30, 2003
posts:3719
votes: 0


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)

Full Member

10+ Year Member

joined:Feb 13, 2003
posts:220
votes: 0


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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members