Hi Guys,

Can someone help me. I am using FCK Editor when I add a new news article to my website. When entering each new article, I have included an option where there is a drop-down list to select a particular news category.

In the front-end of the website the news page displays all news articles from all categories, even if I select a different category for each news article.

My problem is I am stuck on how to display news articles from only the selected category when adding a new article. A solution would enable me to display a news article from any particular news category on any webpage on my website and display another news article from a different category on a different web page.

I suspect it may be a problem with the SQL statement in the content-news code, but I'm not sure as I am not too good at SQL statements.

See attached files: content-news.txt and addnews.txt

Can anyone help me out?

	//include 'unquote.php'; // fixes the backslash appearing in nContent area before an apostrophe or comma. 
		//	fix_magic_quotes();
	if (isset($_POST['cmdSubmit'])) {

		$nTitle = $_POST['txtTitle'];
		$nContent = $_POST['txtContent'];
		$CategoryID = $_POST['cboCategory'];
		$nDate = $_POST['txtDate']; 
			// VALIDATE THE FORM (this is very basic - you are to make the validation more comprehensive)
				$message = "";

			if (empty($nTitle)) {
				$message = $message . "ERROR: Please enter News Title";
			if (empty($nContent)) {
				$message = $message ."<br />ERROR: Please enter News Content";
			if (empty($CategoryID)) {
				$message = $message ."<br />ERROR: Please select News Category";
			if (empty($nDate)) {
				$message = $message ."<br />ERROR: Please enter Correct Date";
			// If no errors, write the record to database
			if ($message == "") {
			//Connect to specified MySQL database
			$db = new mysqli (db_host, db_user, db_password, db_name);
			// Prepare the statement
			$stmt = $db->prepare("INSERT INTO news (nTitle, nContent, CategoryID, nDate) values (?, ?, ?, ?)");
			// Bind parameters (dont change date -= date is a php function!)
			$stmt->bind_param('ssis', $nTitle, $nContent, $CategoryID, $nDate);
			// Execute the statement
			// Close the statement	
		echo $message;
    echo $db->error;
	<form id="frmAddNews" method="post" action="addNews.php">
			<legend>&#160;&#160;Add News Article&#160;&#160;|&#160;<a href="menu.php" class="apageLinks">Main Menu</a>&#160;|&#160;<a href="logout.php" class="apageLinks">Log out</a>&#160;&#160;</legend> 
				<p><br />
					<label>News Title:</label>
						<input type="text" name="txtTitle" size="50" value="" /><br /><br />
					<label>News Category:</label>
						<select id="cbocategory" name="cboCategory">
							<option value="">Select Category&#160;&#160;</option>
							<option value="1">Local News</option>
							<option value="2">Local Events</option>
							<option value="6">Interstate News</option>
						</select><br /> 
					<label>News Content:</label>
						<!--<textarea name="txtContent" cols="30" rows="6"></textarea>-->
							$oFCKeditor = new FCKeditor('txtContent');
							$oFCKeditor->ToolbarSet = 'Normal';
							$oFCKeditor->BasePath = 'fckeditor/';
							$oFCKeditor->Value = '';
						?><br /> 
					<label>Date of Article</label>
					<label>(yyyy-mm-dd)</label><br />
						<input type="text" name="txtDate" size="12" value="" />&#160;&#160;&#160; 
					<input type="submit" name="cmdSubmit" id="cmdSubmit" value="Add News" />
					<input type="reset" name="cmdReset" id="cmdReset" value="Reset" /><br /> 
<!-- End of page content -->
<div class="inner">
					<h2><img src="images/LatestNews.png" width="252" height="40" alt="Our News" /></h2>
						//Connect to specified MySQL database
						$db = new mysqli (db_host, db_user, db_password, db_name);
						// Prepare the statement
						$stmt = $db->prepare("SELECT nTitle, date_format(nDate, '%d %M, %Y'), nContent FROM news order by nDate DESC");

						// Bind parameters (dont change date -= date is a php function!)
						$stmt->bind_result($nTitle, $nDate, $nContent);
						// Execute the statement
						while ($stmt->fetch()) {
							echo "<p> <span class=newstitle> " . $nTitle . "&#160;</span> - (Posted: ";
							echo $nDate. ")<br />";
							echo $nContent. "<br /></p>";
						// Close the statement	
6 Years
Discussion Span
Last Post by davBro

To display only one particular type of news articles in a drop down menu, you need to ensure you have a category table and the news_category compound table in your database where all of the news articles are linked to a category.

Then you can add the WHERE command to your SQL statement:

SELECT nTitle, date_format(nDate, '%d %M, %Y'), nContent FROM news, news_category WHERE category = 1 order by nDate DESC

When doing the match you can use the index of the selected category after getting it from a drop down menu of categories in your PHP code.

Hope that helps.

Edited by StephNicolaou: n/a

|------------------------------|          |-------------------------------------|         |------------------------|
| Categories	          |          | News_Categories		     |         | News	               |
| Category_ID| CategoryName|          | NC_ID | News_ID | Category_ID  |         | News_ID | Title | Date |
-------------------------------|	   |-------------------------------------|         |------------------------|

Howdy stephNicolaou,

Thanks for your reply. It is greatly appreciated. I'll give it a go and send you the results.
Thanks again.


This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.