homepage Welcome to WebmasterWorld Guest from
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

 9:33 pm on Jan 13, 2005 (gmt 0)


I've got this simple problem I'm trying to resolve. Basically what I am trying to achieve is to display 4 categories on one row of the table and then the next four on the next row. I'm using a count variable to determine when to print the next row.

Any ideas?

Here's the code:

<table cellspacing="4" cellpadding="4" border=1>
$result=mysql_query("select cat_name
from quiz_category
where parentid=1
order by cat_name");
while (list($DBcat_name)=mysql_fetch_row($result))
<td valign=top><? echo $DBcat_name?></td>

Many Thanks

W :o)



 9:59 pm on Jan 13, 2005 (gmt 0)

So you need sth like this?

Classical Music¦Poetry¦ Literature ¦Pop
Wars 1800-2005 ¦Films ¦Space travel¦TV series


counter is a good idea. I presume code would be sth like:

$result = mysql_query("SELECT cat_name FROM quiz_category WHERE parentid = '1' ORDER BY cat_name");
$cnt = 1;

while($DBcat_name = mysql_fetch_row($result))
if($cnt == "4")
$cnt = 0;
echo "
<td valign=\"top\">".$DBcat_name[0]."</td>
else echo "<td valign=\"top\">".$DBcat_name[0]."</td>";


it's not the nicest way to do this, but it works

best regards!
Michal Cibor


 10:26 pm on Jan 13, 2005 (gmt 0)

Thanks mcibor,

That does work, I did have a look at the code when its been parsed from the server, and it leaves '<tr><td></td></tr>' at the end, but I can work that out anyway, so thanks.

What I'm trying to do now is to display the subcategories beneath the main category. Now what I have done is created a function so that it calls itself so that it displays the subcategories.

function maketree($rootcatid,$level)
global $cnt;

$sql="select catid,cat_name
from quiz_category
where parentid=$rootcatid
order by cat_name";


echo '<tr>';

while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
echo "<td valign=top>$DBcatname</td>";

if ($cnt==4)
echo '</tr><tr>';


<table cellpadding="2" cellspacing="2" border="1" width="70%">
<? maketree(0,0);?>

Is this the right way?


Woldie :o)

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