Hi all before i get started here is the background of what this script does; Basicly it checks the last post of a forum i made (
http://www.emoforums.net/forum/) and what it does is check for the last post in the forum, if it has replies then select the last info from the replies table if not then use the previous query which takes it from the topics table the problem is that if there is no replies then the $last_info2 doesnt work.
PHP Code:
// to find out if a the latest topic has a reply
$find_topic = mysql_fetch_array(mysql_query("SELECT * FROM `forum_topics` WHERE `forumroot` = '" . $display['id'] . "' ORDER BY `lastdate` DESC LIMIT 1"));
$find_replies = mysql_fetch_array(mysql_query("SELECT COUNT(replies) AS `count` FROM `forum_topics` WHERE `forumroot` = '" . $display['id'] . "' ORDER BY `lastdate` DESC LIMIT 1"));
if ($find_replies['count'] >= '1')
{
$last_info = mysql_fetch_array(mysql_query("SELECT * FROM `forum_replies` WHERE `topic_id` = '" . $find_topic['id'] . "' ORDER BY `id` DESC LIMIT 1"));
$last_info2 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $last_info['starter_id'] . "'"));
$last_info['topic'] = $find_topic['topic'];
}
else
{
$last_info = $find_topic;
$last_info2 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '" . $last_info['starter_id'] . "'"));
}