Hey all,
Firstly, appologies if this is the wrong forum to post this in.
I've followed a tutorial to create a news script. However, I need to add categories to the script. Here is the code:
sql code:
CREATE TABLE news ( id int(10) unsigned NOT NULL auto_increment, postdate timestamp(14) NOT NULL, title varchar(50) NOT NULL default '', content text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate), FULLTEXT KEY content (content) )
News.php:
<?php
$query = "SELECT *," .
"DATE_FORMAT(postdate, '%Y-%m-%d') as date " .
"FROM news ORDER BY id DESC LIMIT $news_limit"; // 1.
$result = mysql_query($query);
while($r=mysql_fetch_array($result)) // 2.
{
echo "<br><table width='100%'><tr bgcolor='$title_cell_color'><td>
<img src='$bullet'><b>$title</b> posted on $date</td></tr>
<tr bgcolor='$news_cell_color'><td>$content<…
</table><br>";
}
?>
add.php:
<?php
include "var.php"; // 1.
if ($action==add) // 2.
{
$title=$POST['title'];
$content=$POST['content']; // 3.
mysql_query("insert into news (title,content) VALUES ('$title','$content')");
echo "<a href='index.php'>Home</a>"; // 4.
}
else // 4.
{
print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td><form name=\"form1\" method=\"post\" action=\"add.php?action=add\">
<div align=\"center\">
<p>Title:
<input type=\"text\" name=\"textfield\">
</p>
<p>News content :
<textarea name=\"title\" cols=\"50\" rows=\"10\" id=\"title\"></textarea>
</p>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Add\">
</p>
</div>
</form></td>
</tr>
</table>\n";
}
?>
var.php:
<?php
//////////////////////////////////////…
$news_limit="xxxx"; // number of news that script shows
$user="xxxx"; // db username
$pass="xxxx"; // password
$db_name="xxxx"; // database name
$bullet="xxxx"; // path to the bullet image
$title_cell_color="xxxx"; // bg color for title cell in RGB...(black = #000000)
$news_cell_color="xxx"; // bg color for news cell in RGB...(black = #000000)
//////////////////////////////////////…
$db = mysql_connect("localhost", "$user", "$pass");
mysql_select_db("$db_name", $db); //
?>
What I need help with, is implementing categories. I want a table for the category, a box on the add form to select the category, and for the news categories to be displayed, and when the link to the category is clicked the news to be displayed. i'm sure it's something simple I just can't figure out how to do it.
Thanks for any and all help, it's much appreciated! !
Ashley