PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi I have the following two functions. the first function displays the topics in the forum. what I would like to do is if the user select one topic and click on it, it will pass the selected topic id to the other function. Here are the codes. what I am getting is blank page in the 2nd function.
<?php
function viewForum() {
if(!($_REQUEST['action']=="viewForum"))return;
$db_connect = mysql_connect("localhost") or die ("Unable to connect to the LocalHost");
$db_select = mysql_select_db("coursework",$db_connect) or die ("Unable to connect to the database");
$query = "SELECT id, title,date_format(date_created, '%b %e %Y at %r') as date,created_by
FROM topic
ORDER BY date_created DESC";
$result = mysql_query($query, $db_connect) or die (mysql_error(). '<br> SQL: '.$sql);
if (!(mysql_num_rows($result))) {
echo "<b>No topics found in the forum </b><br>";
}
else {
echo "<table border=1>";
echo "<tr>";
echo "<th>Posted Topics</th>";
echo "<th>Number of Posts</th>";
echo "</tr>";
while ($posts = mysql_fetch_array($result))
{
$id = $posts['id'];
$title = trim($posts['title']);
$date_created = $posts['date'];
$created_by = trim($posts['created_by']);
$num_replies = "SELECT count(post_id) from post WHERE id = $id";
$result_num_replies = mysql_query($num_replies, $db_connect) or die (mysql_error(). '<br> SQL: '.$sql);
$total_num_replies = mysql_result($result_num_replies,0,'count(post_id)');
echo "<tr>";
?>
<td><A href="<?=$_SERVER['PHP_SELF']?>?action=displayTopic=<?=$id?>"><b><? echo "$title";?></b></a></br>
<? echo "Thread posted on <b>$date_created</b> by <i>$created_by</i>";?>
<td align=center><? echo "$total_num_replies"; ?></td>
</tr>
<?
}
echo "</table>";
}
?>
<p>
<A href="<?=$_SERVER['PHP_SELF']?>?action=Cancel">Go Back</A>
<A href="<?=$_SERVER['PHP_SELF']?>?action=submitTopic">Create New Topic</A><br>
</p>
<?
}
?>
and the code for the second function is as follows (i removed all the code as it is more than 100 lines just used the first line for debugging
Here url eill be converted to a variable filed ($_GET['url']) when the script starts.
With the '&' symbol you can separate the variables to be passed by the query string, like this: