So this is my learning project, and currently.. I'm asking for "inspecific" help so if anyone is willing to look things over and give me some pointers that would be great. I do have a few specific questions if anyone wants to answer those, that I haven't been able to find answers to yet. First I'll ask those questions and then go into some of my current code (which is not even close to done). But I want to get practices down well if anyone is interested in helping me do that.
Q: When I pass 2 functions into a function that doesn't "require" paramters.. for some reason the entire page doesn't come out at the end. The html that I see clearly shows this occuring, and yet it isn't like a normal parse error where i get nothing back.
Here's a snippet of the problem
<? renderbody(func_get_arg(0),func_get_arg(1)); ?>
I'm sure it's something basic and my lack of syntax knowledge is the cause, but anyway.. if someone could answer why and how to deal with that it'd be great. Actually, not so much necessary to tell me how to deal with as what I did is just passed vars containing those values and that worked, I just want to know why I can't use the functions in there directly.
Ok, now here is my entire code. Currently I have a basic working database format for just the index (list of forums/sections) page of the forum.
I'm expanding to the topics listing next, then posts, and then probably onto user management, etc. Not sure if that's the best way to go about it or not, but while I could just read code from another forum out there, I find that if I get too much from the outside there is just so much I don't understand how it works, and this way I get a good idea of why certain things are done. Now I'll probably end up starting over this way, but at least I understand things.
Here is the forum.php (the page someone goes to)
<html> <?
require "config.php";
echo "<header><title>".$title."</title></header>";
require "render.php";
$parm;
$request = $_GET['forum'];
if($request)
$parm='forum';
else{
$request = $_GET['section'];
if($request)
$parm='section';
}
if($request){ render($parm, $request); }
else
render();
?> </html>
Here is render.php which "renders" the page
<?php
/* This file contains the forum rendering engine, currently only for the main index */
function renderheader(){
?> <table align="middle" width="95%" border="1" bgcolor="Black" cellpadding="1" cellspacing="1" bordercolor="Green">
<TR>
<TD colspan="2"align="middle"><img src="logo.jpg"></TD>
</TR>
<TR>
<TD align="left"> UserInfo </TD> <TD align="right"> Controls </TD>
</TR>
</table>
<table align="middle" width="95%" border="0" bgcolor="Black" cellpadding="1" cellspacing="1" bordercolor="Green">
<TR>
<br> <br> <br>
</TR>
<TR>
<TD><a href="forum.php">Forum</a></TD>
</TR>
</table>
<? }
function renderbody($type,$target){
require "config.php";
$argcount = func_num_args();
$type = func_get_arg(0);
$target = func_get_arg(1);
// Specific section or entire index
if($type == 'section'){
$query = "SELECT position, name, id FROM `sections` WHERE id=$target ORDER BY position ASC";
}
else if($type == 'forum'){
$query = "forum";
}
else{
$query = "SELECT position, name, id FROM `sections` ORDER BY position ASC";
}
if($query != 'forum'){
$link = mysql_connect($host, $user, $pass);
if(!$link){ die('Could not connect: '.mysql_error()); }
$select = mysql_select_db($dbname,$link);
if(!$select){ die('Could not select: '.$dbname.' '.mysql_error()); }
$resultset = mysql_query($query);
while($current = mysql_fetch_array($resultset, MYSQL_ASSOC)){
?> <table align="middle" width="95%" border="1" bgcolor="Black" cellpadding="1" cellspacing="1" bordercolor="Green">
<TR>
<TD colspan="5"><? echo $current['name']; ?></TD>
</TR>
<TR>
<TD height="30" width="8%"></TD>
<TD width="46%"> <b>Forum</b> </TD>
<TD align="center" width="6%"> <b>Topics</b> </TD>
<TD align="center" width="6%"><b>Replies</b></TD>
<TD width="24%"><b>Last Post</b></TD>
</TR>
<? $query2="SELECT position, name, topics, posts, section, id FROM `forums` WHERE section=$current[id] ORDER BY position ASC";
$link2 = mysql_connect($host, $user, $pass);
if (!$link2) { die('Could not connect: ' . mysql_error()); }
$select2 = mysql_select_db($dbname,$link2);
if(!$select2){ die('Cannot select '.$dbname.' : '.mysql_error()); }
$resultset2 = mysql_query($query2) or die("Query failed: ".mysql_error());
while($current2 = mysql_fetch_array($resultset2, MYSQL_ASSOC)){
?> <TR>
<TD height="50"></TD>
<TD><? echo "<a href='forum.php?forum=$current2[id]'>".$current2['name']."</a>"; ?></TD>
<TD><? echo $current2['topics']; ?></TD>
<TD><? echo $current2['posts']; ?></TD>
<td><? echo "Whatever post here"; ?></td>
</TR>
<? }
mysql_close($link2);
?><BR><BR><?
}
mysql_close($link);
?> </table>
<? }
}
function render($parm,$target){
?> <body text="Lime" bgcolor="Black">
<table align="middle" height="100%" width= "95%" border="2" bgcolor="Black" cellpadding="1" cellspacing="1" bordercolor="Green">
<TR>
<TD valign="top">
<? renderheader(); ?>
<? renderbody($parm,$target); ?>
</TD>
</TR>
</table>
</body>
<? }
?>
<?
$host='localhost';
$user='root';
$pass='pass';
$dbname='forum';
$title='A Test Forum';
?>
And this is just configuration info, like one would expect to use when installing the forum. Though I'm sure I'll probably make an install script so no one has to edit it directly. Thanks for any help and of course I don't expect a lot, I'll get along but I wouldn't mind some pointers if anyone has time.