Location: PHPKode > projects > PHP Simple FAQ > phpsimplefaq1.1beta/phpsimplefaq/includes/faq_qa.inc.php
<? 	// PHP Simple FAQ Question and answer page v1.0

$get_cat = "SELECT *
			FROM $database_name.$category_table
			WHERE cat_id='$category'";
$cat_result = mysql_query($get_cat,$connection);
$myrow1 = mysql_fetch_array($cat_result);
$this_category = $myrow1["category"];
$cat_id = $myrow1["cat_id"];
$faq_id = $myrow1["faq_id"];
$get_faq = "SELECT *
		    FROM $database_name.$faq_table
		    WHERE faq_id='$faq_id'";
$faq_result = mysql_query($get_faq,$connection);
$myrow2 = mysql_fetch_array($faq_result);
$faq_title = $myrow2["faq_title"];
if (($add == "question") && ($message != "")) 

	{
		if ($php_simplefaq_email) 
		
			{
			   $user_sql="SELECT user_name
						  FROM $database_name.$user_table
						  WHERE user_email='$php_simplefaq_email'";
			   $user_result = mysql_query($user_sql,$connection);
			   $myrow3 = mysql_fetch_array($user_result);
			   $posted_by = $myrow3["user_name"];
			}
			
		if (!$posted_by)
			
			{
				$posted_by = "$anon_user";
			}
		
		$check_question = "SELECT question
						   FROM $database_name.$question_table
						   WHERE question = '$message' AND cat_id = '$cat_id'";
		$check_result = mysql_query($check_question,$connection);
		$check_num1 = mysql_numrows($check_result);
		
		if ($check_num1 == 0) 
		
			{
				$new_question = "INSERT INTO $database_name.$question_table 
								 (question, posted_date, cat_id, posted_by)
								 VALUES 
								 ('$message', '$date', '$cat_id', '$posted_by')";
				mysql_query($new_question,$connection);
				$newest_question = "$message";
			}
			
	} elseif ($add == "question") 
	
		{
			$add_question = "true";
		}
		
?>

<table border="0" width="100%" cellspacing="2" cellpadding="2">
	<tr valign=top align=left>
	   <? echo "<td><font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">" ?>
	   <center><b><? echo "<a class=\"psf\" href=\"index.php\">$main_title</a> > <a class=\"psf\" href=\"index.php?action=qa&faq=$faq_id\">$faq_title</a> > $this_category"; ?></b><br>
	   <? if (($add == "question") && ($message == "")) { echo "<font color=\"red\">$blank_question_lang</font>"; } ?>
	   <? if (($check_num1 != 0) && ($add == "question")) { echo "<font color=\"red\">$duplicate_question_lang</font>"; } ?></center></font></td>
	</tr>
</table>
<table border="0" width="90%" cellspacing="2" cellpadding="2">
	<tr>
	   <td align=left><? echo "<font class=\"G10\"><a class=\"psf\" href=\"index.php?action=qa&category=$cat_id&add_question=true#question\">$add_question2_lang</a></font></td>"; ?>
	   <td align=right><? echo "<font class=\"G10\"><a class=\"psf\" href=\"index.php?action=qa&faq=$faq_id\">$view_faq_lang</a></font></td>"; ?>
	</tr>
</table>
<center>
<table width="90%" cellpadding="4" cellspacing="2" bgcolor="#333366">
   <tr>
	   <td align="LEFT" bgcolor="#3366CC"><b><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\" color=\"#FFFFFF\">$question_title_lang</font></b></td>"; ?>
	   <td align="LEFT" bgcolor="#3366CC" width="100" nowrap><b><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\" color=\"#FFFFFF\">$posted_by_lang</font></b></td>"; ?>
   </tr>				
	   <? 
		   $get_q = "SELECT * 
					 FROM $database_name.$question_table 
					 WHERE cat_id='$cat_id'";
		   $result = mysql_query($get_q, $connection);
		   $q_total = mysql_numrows($result);
		   if ($q_total == 0)
					 
				{
	
	?>						

	<tr>
	   <td align="LEFT" valign="TOP" bgcolor="#DDDDDD"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">$no_questions_lang."; ?></font></td>
	   <td align="LEFT" valign="TOP" bgcolor="#DDDDDD" widht="170"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">$posted_by"; ?></font></td>
	</tr>

    <? 
				}
				
		   while ($myrow3 = mysql_fetch_array($result)) 
		   
		   		{
					 $question = $myrow3["question"];
					 $q_id = $myrow3["question_id"];
					 $posted_by = $myrow3["posted_by"];
					 $rating = $myrow["rating"];
					 $get_a = "SELECT * 
							   FROM $database_name.$answer_table 
							   WHERE q_id='$q_id'";
					 $result_a = mysql_query($get_a, $connection);
					 $a_total = mysql_numrows($result_a);	 
					 
					 if ($a_total == 1) 
					 
					 	 {	 
							 $a_num = "$a_total $answer_lang";
						 } else {
							 $a_num = "$a_total $answers_lang";
						 }
	   ?>						

	<tr>
	   <td align="LEFT" valign="TOP" bgcolor="#DDDDDD">
	   		<table width="100%" cellpadding="0" cellspacing="0" border="0">
	   			<tr>
	   				<td align="LEFT" valign="TOP" bgcolor="#DDDDDD"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">$question - <a class=\"psf\" href=\"index.php?action=answers&category=$category&q_id=$q_id\"><I>$a_num</I></a>"; ?></font></td>
	   				<td align="RIGHT" valign="TOP" bgcolor="#DDDDDD" width="90"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\"><a class=\"psf\" href=\"index.php?action=answers&category=$category&q_id=$q_id\">$answer_this_lang</a></font>"; ?>
	   			</tr>
	   		</table>
	   	</td>
	   <td align="LEFT" valign="TOP" bgcolor="#DDDDDD" width="170"><? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">$posted_by"; ?></font></td>
	</tr>

     <? 

				} 

?>

</table>
<table border="0" width="90%" cellspacing="2" cellpadding="2">
	<tr>
	   <td align=left><? echo "<font class=\"G10\"><a class=\"psf\" href=\"index.php?action=qa&category=$cat_id&add_question=true#question\">$add_question2_lang</a></font></td>"; ?>
	   <td align=right><? echo "<font class=\"G10\"><a class=\"psf\" href=\"index.php?action=qa&faq=$faq_id\">$view_faq_lang</a></font></td>"; ?>
	</tr>
</table>

<? 

if ($add_question == "true") 

	{ 
	
?>

	<br>
	<br>
	<br>
	<a name="question"></a>
	<form name="form1" method="post" action="index.php?action=qa&category=<? echo "$category" ?>&add=question">
	<table width="90%" cellpadding="4" cellspacing="2" bgcolor="#FFFFFF">	
		<tr>
		   <td valign="TOP" align="LEFT" bgcolor="#FFFFFF">
		   <? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\"><b>$add_question3_lang:</b></font></td>"; ?>
		</tr>
		
		<tr>
		   <td valign="TOP" align="LEFT" bgcolor="#FFFFFF"><textarea rows="6" name="message" cols="70"></textarea></td>
		</tr>
		<? if (!$php_simplefaq_name) { ?>
		<tr>
		   <td valign="TOP" align="LEFT" bgcolor="#FFFFFF"><INPUT TYPE="text" NAME="posted_by" CLASS="add_style">
		   <? echo "<font face=\"$font_face\" size=\"$font_size\" class=\"$font_class\">&nbsp;$name_check_lang</td>"; ?>
		</tr>
		<? } ?>
		<tr>
		   <td valign="TOP" align="LEFT" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="<? echo "$submit_button_lang"; ?>"></td>
		</tr>
	</table>
	</form>
	
	<? } ?>	
	
	</center>
	
<?

if (($admin_email == "Yes") && ($add == "question") && ($message != ""))
				
	{
		// Email the admin for new answer
		$email_sql = "SELECT user_email
					  FROM $database_name.$user_table
					  WHERE user_admin = 'Yes'";
		$email_result = mysql_query($email_sql,$connection);				
		
		while ($my_email = mysql_fetch_array($email_result))
		
			{
				$email = $my_email["user_email"];
				$message = "<a href=\"$absolute_url/index.php?action=answers&category=$cat_id&q_id=$q_id\">$question_title_lang</a>: " . stripslashes($newest_question) . "<br>\n";
				$message .= "<i>$posted_by_lang $posted_by</i><br><br><br>\n\n\n";
				$message .= "<a href=\"$absolute_url\">$main_title</a><br>\n";
				$message .= "<font size=\"2\" color=\"#666666\"><a href=\"http://sourceforge.net/projects/phpsimplefaq/\">PHP Simple FAQ</a> $phpsf_version</font><br>\n";
				$subject = "$email_question_lang";
				$mailheaders = "From: $main_title <$email>\n";
				$mailheaders .= "Reply-To: $email\n";
				$mailheaders .= "Content-type: text/html; charset=iso-8859-1\r\n";
				Mail($email, $subject, $message, $mailheaders);
			}
	}
	
?>
Return current item: PHP Simple FAQ