Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: Displaying MySQL data across tables...


Message #1 by "Kyle" <bige88fan@c...> on Sat, 19 Oct 2002 19:06:12
Hello again. THis one is a little easier than my previous questions...(I 
think/hope). Basically what I am trying to do is take parent categories 
and their sub-categories from MySQL data, and display them across tables. 
I know how to do it partially, but not the way that I need to do it. Here 
is what I am confused by. 

Lets say I have 4 Parent categories, each having their own sub-categories. 
I want them to be displayed in columns of 2. Sort of like this.

PARENT 1 | PARENT 2
-sub1    | -sub1
-sub2    | -sub2

____________________
PARENT3  | PARENT 4
-sub1    | -sub1
-sub2    | -sub2

____________________

Can you guys understand that? hope so:) 

here is my current code for fetching the sub-category and category arrays:

//Execute a couple of queries in order to generate categoriy parents w/subs
$query = mysql_query("SELECT DISTINCT title,headingid FROM cat_headings 
WHERE game='$game' ");

while($cat1 = mysql_fetch_array($query)){
$parent[] = $cat1["title"];
$id[] = $cat1["headingid"];
}
mysql_free_result($query);
unset($cat1,$query);

$count = count($id);

$dump_data .= "<table cellpadding=\"0\" cellspacing=\"0\" border=\"$get
[bordersz]\" bordercolor=\"$get[borderclr]\" valign=\"top\"><tr>";
for($i=0;$i<$count;$i++){

if (($counter++ % 2) != 0) {
		$begin = "<td>";
                $end = "</td></tr>";
	} else {
		$begin = "<td>";
                $end = "</td>";
	} 

$dump_data .= "
$begin<font size=\"3\" color=\"$get[pagetxt_color]\">$parent[$i]
</font>$end";

//within the loop, get categories belonging to parent
$query = mysql_query("SELECT DISTINCT catname,catprefix FROM categories 
WHERE headingid='$id[$i]' ORDER BY catname ASC");
while($result = mysql_fetch_array($query)){
$sub = $result["catname"];
$pre = $result["catprefix"];
$dump_data .= "
<tr><td><font size=\"2\"><a href=\"$PHP_SELF?\" title=\"$sub\" 
style=\"Color: $get[pagetxt_bldcolor]; Font-Weight: Bold\">
               $sub</a></font><br></td></tr>";

	}
   }
$dump_data .= "</table>";
do_template($dump_data);
}

As you can see, I tried with the use of this code:
if (($counter++ % 2) != 0) {
		$begin = "<td>";
                $end = "</td></tr>";
	} else {
		$begin = "<td>";
                $end = "</td>";
	} 

To set up a endpoint-begin point marker for where the tables/<td>'s should 
end, but didn't work:( Help appreciated,

-Kyle.



  Return to Index