Jump to content

Update, but check if there is subcategory


eevan79

Recommended Posts

I need help for updating last topic from categories. Problem is that first must check if there is latest topic from subcategory.

 

Table for updating: categories

 

Here is my script

UPDATE ".$table_prefix."categories 
SET cat_last_post_subject='".$tsubject['topic_subject']."', 
cat_last_poster_name= '".$userposted['user_name']."', cat_last_poster_id=".$userposted['user_id'].", 
cat_last_post_date = NOW(), 
cat_last_topic_id = ".$tsubject['topic_id']."  

WHERE cat_id=" .$tsubject['topic_cat']."

 

But first I must check if cat_id have cat_parent. If true than update that post ifcat_last_post_date is newer than first.

 

To explain what is cat_parent:

If cat_parent is 0 than thats root category. If cat_parent have number, that number is ID of root category.

For example if there is filed cat_id 10 and cat_parent 3, that means category with cat_id 3 have subcategory with cat_id 10...

 

How to check if there is newer post in subcategory than root?

 

EDIT: to make more clear. First must be select recent post (considering cat_id and cat_parent).

 

SELECT 
cat_id, 
cat_name, 
cat_description, 
cat_icon, 
cat_parent, 
cat_child, 
cat_child, 
cat_last_post_subject,
cat_last_topic_id, 
cat_last_poster_name, 
cat_last_poster_id, 
cat_last_post_date
FROM
categories
WHERE
cat_id = ".$row['cat_id']."
ORDER BY cat_last_post_date DESC LIMIT 0,1

But if it have cat_parent > 0 (have subcategory), check/select that cat_id (cat_parent) for recent post.

That means post in subcategory is with recent date than category.

:shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.