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:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.