Welcome,
I'm working on a content management system for mymultiplayer gaming Clan Site, and I was going to use templates similar to those in Phpbb or Invision. Basically my problem is that I want to make mysql-based links menu divided into categories. I was trying to use template engine provided by Polerio Babao in one of articles on this site: http://www.phpbuilder.com/columns/babao20020907.php3 .
What I want to get is (simplified) something like this:
<!-- BEGIN category -->
{CATEGORY_NAME}<br>
<!-- BEGIN links --->
<a href="{URL}">{LINK_NAME}</a><br>
<!-- END links -->
<br><br>
<!-- END category -->
It means I have to query mysql database more or less this way:
$query = mysql_query("SELECT * FROM category");
while ($row = mysql_fetch_array($query)) {
$links_query = mysql_query("SELECT * FROM links WHERE category = $row[name]");
while ($links_row = mysql_fetch_array($links_query)) {
// ...
}
}
It does work quite nice while I'm using "echo" to print all the stuff, but now I want to move whole site into templates and have really no idea how to do it... Above-mentioned templates don't work so great, beacuse links do not stick to their categories, but the same ones get in all categories. I hope some of You can help me with this. :rolleyes:
Here is what I have now and what doesn't work as I want it to 😃 :
left.php
$file='template/' .$userstyle . '/left.tpl';
$LoadTemplate = LoadTemplate($file);
// Get Cats info...
$query = mysql_query("SELECT * FROM categories ORDER BY position ASC");
$n = mysql_num_rows($query);
for ($x='0' ; $x<$n ; $x++) {
$sql = mysql_fetch_array($query); $result[$x] = array($sql[name]); $help[$x] = $sql;
}
if(!$result) $LoadTemplate = EmptySpace("01", $LoadTemplate); // If this does not exist, table w/o value will exist
else {
$Prefix = "1a";
$RowValue = $result;
$RowName = array("{TITLE}");
$LoadTemplate = DynamicRows($Prefix, $LoadTemplate, $RowName, $RowValue);
}
for ($x='0' ; $x<$n ; $x++) {
// !!!
// And links info...
$arg = $help[$x];
$query2 = mysql_query("SELECT * FROM menu WHERE category = '$arg[name]' ORDER BY position ASC");
$n2 = mysql_num_rows($query2);
for ($x2='0' ; $x2<$n2 ; $x2++) {
$sql2 = mysql_fetch_array($query2);
if ($sql2[new_window] == '1') { $newwwindow = 'target="_blank"'; } else { $newwindow = '';}
$result2[$x2] = array($sql2[url],$sql2[nazwa],$newwwindow);
}
//$result2='';
if(!$result2) $LoadTemplate = EmptySpace("00", $LoadTemplate); // If this does not exist, table w/o value will exist
else {
$Prefix2 = "0a";
$RowValue2 = $result2;
$RowName2 = array("{URL}","{NAME}", "{NEWWINDOW}");
$LoadTemplate = DynamicRows($Prefix2, $LoadTemplate, $RowName2, $RowValue2);
}
// !!
}
$left = $LoadTemplate;
echo $left;
And the template file:
left.tpl
<TD vAlign=top width=243>
<!--%00_BEGIN_NO_MESSAGES%-->
<!--%01_BEGIN_NO_MESSAGES%-->
<!--%1a_BEGIN_MESSAGE_LIST%-->
<!--%1a_ML_LOOPBEGIN%-->
<TABLE cellSpacing=0 cellPadding=0 width=243 border=0>
<tr>
<TD class=subjectcell width=243
background=template_img/IB-II/tlo1.gif height=48>
<br><p align="center" style="text-indent: 0; line-height: 100%; word-spacing: 0; margin: 0">
</center>
<p align="center" style="text-indent: 0; line-height: 100%; word-spacing: 0; margin: 0"><strong>{TITLE}</strong></TD>
</tr>
<CENTER>
<tr>
<TD class=newscell
background=template_img/IB-II/menutlo.gif> <p align="center">
<!--%00_BEGIN_NO_MESSAGES%-->
<!--%0a_BEGIN_MESSAGE_LIST%-->
<!--%0a_ML_LOOPBEGIN%-->
<a href="{URL}" {NEWWINDOW}><font color="#808080">{NAME}</font></a><br>
<!--%0a_ML_LOOPEND%-->
<!--%0a_END_MESSAGE_LIST%-->
<!--%00_END_NO_MESSAGES%-->
</TD>
</tr>
<tr>
<TD background=template_img/IB-II/dol.gif
height=22></TD>
</tr>
</TABLE>
<!--%1a_ML_LOOPEND%-->
<!--%1a_END_MESSAGE_LIST%-->
<!--%01_END_NO_MESSAGES%-->
<!--%00_BEGIN_NO_MESSAGES%-->
</TD>
As I wrote above, links come in all cats, not only in those where they should 😃 Anyway, I won't be suprised I've done a silly mistake... So I hope someone will be able to help.
Thanks in advance,