eevan79 Posted July 8, 2010 Share Posted July 8, 2010 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. Link to comment https://forums.phpfreaks.com/topic/207173-update-but-check-if-there-is-subcategory/ Share on other sites More sharing options...
fenway Posted July 9, 2010 Share Posted July 9, 2010 And you can't just join in those tables? Link to comment https://forums.phpfreaks.com/topic/207173-update-but-check-if-there-is-subcategory/#findComment-1083541 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.