homepage Welcome to WebmasterWorld Guest from 54.145.183.190
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Display data from DB - Formatting Issue
woldie

10+ Year Member



 
Msg#: 4799 posted 11:30 am on Aug 19, 2004 (gmt 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)

 

Paul in South Africa

10+ Year Member



 
Msg#: 4799 posted 11:58 am on Aug 19, 2004 (gmt 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>

dreamcatcher

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



 
Msg#: 4799 posted 12:00 pm on Aug 19, 2004 (gmt 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.

woldie

10+ Year Member



 
Msg#: 4799 posted 12:11 pm on Aug 19, 2004 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved