Forum Moderators: coopster

Message Too Old, No Replies

CMS kinda stuff.

         

FnTm

7:57 am on Aug 22, 2007 (gmt 0)

10+ Year Member



Hi again dear Webmasters. I have great problem on my hands. I made a cms for myself, with lotsa new stuff for me, but there is one thing that bothers me. The categories.

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?

Habtom

11:18 am on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, what I understood is the following. Somehow you are adding the categories into the database and with that part you are fine. When you want to start using the categories (lets say while posting a story), you need the list of the categories to be in that form including the newly added ones.

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

FnTm

12:31 pm on Aug 22, 2007 (gmt 0)

10+ Year Member



No, that is not really what I wanted.

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.

Habtom

12:35 pm on Aug 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

FnTm

6:24 am on Aug 23, 2007 (gmt 0)

10+ Year Member



Thanks, for the reply, but when I try to get it to work, I get this kind of error

Error : Column 'id' in where clause is ambiguous

I of course assumed, that I had to modify the query, didnt, I?

Habtom

6:43 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is your current query?

FnTm

8:01 am on Aug 23, 2007 (gmt 0)

10+ Year Member



$query= "SELECT cms.id, cms.title, cms_cat_list.category FROM cms_cat_list, cms WHERE cms.category = cms_cat_list.id order by id desc limit 5";
$result= mysql_query($query) or die('Error : ' . mysql_error());
while($row1 = mysql_fetch_array($result))

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?

Habtom

8:07 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$query= "SELECT cms.id, cms.title, cms_cat_list.category FROM cms_cat_list, cms WHERE cms.category = cms_cat_list.id order by cms_cat_list.id desc limit 5";

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>";

henry0

11:14 am on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sometimes it is useful to echo your query and plug it in (for ex:) phpMyAdmin

FnTm

11:25 am on Aug 23, 2007 (gmt 0)

10+ Year Member



something strange happened, and now I dont even see any of my entries...

ehh... seems like im going to stick with the manual add, and stop wasting your time.

Thanks anyway.

[edited by: FnTm at 11:27 am (utc) on Aug. 23, 2007]

henry0

5:21 pm on Aug 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



did you echo your query
post the result

FnTm

6:10 am on Aug 24, 2007 (gmt 0)

10+ Year Member



Yeah, I echoed my query :D

It just turned up empty, but there were 3 records in the database.

But its ok. Ill work with what ive got here, and do it manually.