Forum Moderators: coopster
Right now, I have to add categories through a form (which I made) nad it then posts the category in table called cms_cat_list.
Then I add a story, or a newspiece, and I select a category id to add to the story, and then It all goes to table cms.
End of the story, and start of the problem.
As I wanted to output my stories in fields with their category name, I had to do the scripting manually. But what i want, is that it would output the category id on the index page as soon as it is made, and as soon as a story is added to the category, It would ouptu there. Now im doing it manually by writing the query by hand everytime I add a category.
so here is my code at the moment:
echo "<table border=\"0\" cellspacing=\"4\" width=\"100%\"><tr><td style=\"border:1px solid #C4CFCF;\" valign=\"top\" width=\"50%\">";
$query3= "SELECT * FROM cms_cat_list where id='6' ORDER BY id desc limit 5";
$result3= mysql_query($query3) or die('Error : ' . mysql_error());
while($row3 = mysql_fetch_array($result3))echo "<font class=\"text6\">".$row3['category']."</font>";
$self= $_SERVER['PHP_SELF'];
$query= "SELECT * FROM cms where category='6' ORDER BY id desc limit 5";
$result= mysql_query($query) or die('Error : ' . mysql_error());
while($row = mysql_fetch_array($result))
echo "<br><br><font class=\"header1\"><a href=\"mysite.com/index.php?id=".$row['id']."\">".$row['title'] . "</a></font>";
//echo $teksts;
/*************************************** Shows the first 5 records form category 7******************/
echo "</td>";
echo "<td style=\"border:1px solid #C4CFCF;\">";
$query4= "SELECT * FROM cms_cat_list where id='7' ORDER BY id desc limit 5";
$result4= mysql_query($query4) or die('Error : ' . mysql_error());
while($row4 = mysql_fetch_array($result4))
echo "<font class=\"text6\">".$row4['category']."</font>";
$query7= "SELECT * FROM cms where category='7' ORDER BY id desc limit 5";
$result7= mysql_query($query7) or die('Error : ' . mysql_error());
while($row7 = mysql_fetch_array($result7))
echo "<br><br><font class=\"header1\"><a href=\"mysite.com/index.php?id=".$row7['id']."\">".$row7['title'] . "</a></font>";
echo "</td></tr></table>";
And this creates a row with 2 colums that output the stories.
Any ideas?
If that is the case, go to the section where you want to display the categories >
You could use the following as an example:
$sql = "SELECT category from table";
$row = mysql_query($sql);
$options ="<select>";
while($rows = mysql_fetch_array($row) {
$options .= "<option>". $rows['category'] ."</option>";
}
$options .="<select>";
and then print $options where your list of categories should be.
Habtom
A little more explanation. I created my index page with lotas queries.
what u saw i a query, that creates 2 new field for 2 categories on my front page.
but when I add new categoryies, I have to copy/paste this script once more, just to add those extra fields, and I have to edit the queries, to make them read the right field.
Here is what I want in my code, but I dont know how to do that.
Check table cms_cat_list for categories, echoes them, then looksup at cms and searches for articles where cat_id= cat_id from cms_cat_list, that way echoing the right stories in the right categories.
Tried to do that myself, but failed miserably.
Check table cms_cat_list for categories, echoes them, then looksup at cms and searches for articles where cat_id= cat_id from cms_cat_list, that way echoing the right stories in the right categories.
I hope this time I get closer to what you want :)
You might put it in just one query:
SELECT CM.article, CL.category FROM cms_cat_list CL, cms CM WHERE CM.cat_id = CL.cat_id
echo "<br><br><font class=\"header1\"><a href=\"www.mysite.com/blogs/index.php?id=".$row1['cms.id']."\">".$row1['title'] . "</a>";
So this is what happens.It does output the articles I wanted. With some tweaking I think it would allso show exactly what I wanted, table with articles for each category I entered. But there is just one problem... It would show them in a long line of tables, but I would rather preffer them to align in two colums... is it possible?
The error is due to the id, see the bold part. If I used the wrong table, modify it.
Something like the following should do it for you:
$result= mysql_query($query) or die('Error : ' . mysql_error());
$table = "<table>";
$switch = 0;
while($row1 = mysql_fetch_array($result))
$switch=0?$table.="<tr><td>{data here}</td>":$table.="<td>{data here}</td></tr>";
}
$table.="</table>";