Hello all,
To begin with, I would like to say that I am working on a forum type project without any prior knowledge of PHP.
What I am trying to do is have a page set up as a table. In the cells of that table I have php variables ($topMenu, $sideMenu, and $pageContent). These variables need to change depending on what is clicked.
(I have variables for buttons, and variables for other tables, etc. to be displayed upon clicking the buttons)
So right now a user can log in (at which point what I want the user to see is the latest 2 messages posted in the $pageContent variable). The problem is, the way the forum displays things right now, which is by looping through the database content and extracting the data incrementally. SO, in order to view the posts I would need to echo from inside the loop, however I don't want it to display the posts then, I want them listed in the $pageContent variable. Problem is, the only way I could think of putting the entire loop into a variable (i.e. $messages) would be by converting the entire loop into a string. However, when I do so, the php code does not work as I'd like...it simply remains hidden inside the source code of the page...whereas I'd like it to function.
Here is my loop code...
for($i=0; $i < $messageNum; $i++){
$message_id=mysql_result($messageResult,$i,"message_id");
$message_title=mysql_result($messageResult,$i,"message_title");
$message_time=mysql_result($messageResult,$i,"message_time");
$message_date=mysql_result($messageResult,$i,"message_date");
$message_content=mysql_result($messageResult,$i,"message_content");
//Button to enable comments.
$enable_comments="
<form name=\"showComments\" method=\"post\">
<input type=\"Hidden\" name=\"enableComments\">
<input type=\"Hidden\" name=\"comment_origin\" value=\"$message_title\">
<input type=\"submit\" value=\"Show Comments\"></form>";
//Button to disable comments.
$disable_comments="
<form name=\"hideComments\" method=\"post\">
<input type=\"Hidden\" name=\"disableComments\">
<input type=\"Hidden\" name=\"comment_origin\" value=\"$message_title\">
<input type=\"submit\" value=\"Hide Comments\"></form>";
//If the user clicks on "show comments"
if (isset($_POST['enableComments'])) {
//the button changes to "hide comments"
$commentButton = $disable_comments;
//and if the user clicks on "hide comments"
} elseif (isset($_POST['disableComments'])) {
//change the button to "show comments"
$commentButton = $enable_comments;
//otherwise show "show comments" by default.
} else {
$commentButton = $enable_comments;
}
$messageTable="
<center>
<table bgcolor=\"CCCCCC\" width=\"548\" height=\"240\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td class=\"title\" height=\"30\">$message_title</td>
<td class=\"time\" height=\"30\">$message_time</td>
<td class=\"date\" height=\"30\">$message_date</td>
</tr>
<tr>
<td colspan=\"3\" class=\"content\" background=\"images/centre.png\" height=\"140\">$message_content</td>
</tr>
<tr>
<td width=\"20%\" height=\"28\">
<form action=\"messageEdit\" method=\"post\">
<input type=\"Hidden\" name=\"edit_message\" value=\"$message_id\">
<input type=\"button\" value=\"Edit\">
</form></td>
<td width=\"20%\" height=\"28\">
<form action=\"messageDelete.php\" method=\"post\">
<input type=\"Hidden\" name=\"del_message\" value=\"$message_id\">
<input type=\"button\" value=\"Delete\">
</form></td>
<td width=\"20%\" height=\"28\">$commentButton</td>
</tr>
<tr>
<td colspan=\"3\">$commentTables</td>
</tr>
</table>
</center>
<br><br>";
echo $messageTable;
}
basically, I'd like to store that entire loop into a variable called $messages, and then make $pageContent in another file equal to $messages in order to display the posts.
If anyone could please help me out, that would be great. :bemused:
Thanks in advance,
-Khael