Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: how to select subcat in function articles?  (Read 186 times)

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
how to select subcat in function articles?
« on: February 14, 2013, 04:02:51 PM »

Hello

Is there any way to select subcat in function articles with out make a new query?

I use this function but need to eliminate this query

Code: [Select]
function catsubcat(){
global $_catID;
$query = "SELECT subcat FROM "._PRE.'categories'." WHERE id = '$_catID' ";
$result = mysql_query($query);
$r = mysql_fetch_array($result);
$catsubdata = $r['subcat'];
return $catsubdata;
}

Any idea?
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: how to select subcat in function articles?
« Reply #1 on: February 15, 2013, 12:11:32 AM »

Without a query? You can add a global array in the categories function and add the relevant subcategories from the current category in the array for use later on.

Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: how to select subcat in function articles?
« Reply #2 on: February 15, 2013, 05:58:08 PM »

Thanks nukpana, but seems like is not fit to my needs.
I think I add a new column to hold this, pitty that can't get it by $MainQuery
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: how to select subcat in function articles?
« Reply #3 on: February 15, 2013, 11:51:27 PM »

Perhaps, I may not be fully understanding what it is you are looking for or looking to do. Care to explain it better or give a user case scenario to help me visualize - perhaps your approach may not be what you need to accomplish what you are trying to do.
Logged

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: how to select subcat in function articles?
« Reply #4 on: February 16, 2013, 08:42:09 AM »

Well, I use the following code in function articles with the above function catsubcat()

the point Is to separate a category and all the subcat that bellong to this (in this example cat5) and make it appear with different styling

Code: [Select]
<?php
if ($r['displaytitle'] == 'YES') {
if (!$_ID)  {
                                    if(
$_catID == || catsubcat() == 5){
     echo '<h2 class="big">'.$link.$uri.'/'.$r['asef'].'/">'.$title.'</a></h2>';
                                       } else {
                                             echo 
'<h2 class="small">'.$link.$uri.'/'.$r['asef'].'/">'.$title.'</a></h2>';
                                        }
   } else {
                                        if(
$_catID == || catsubcat() == 5){
     echo '<h2 class="big">'.$title.'</h2>';
                                        } else {
                                             echo 
'<h2 class="small">'.$title.'</h2>';
                                        }
}
}

?>

all the subcat for category 5 takes the same number in categories, but I can't find one way to select this subcat without an extra query
I use catsubcat() also in comments, rss, etc.
« Last Edit: February 16, 2013, 09:01:36 AM by sibas »
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: how to select subcat in function articles?
« Reply #5 on: February 17, 2013, 08:14:38 AM »

You can use the $categorySEF insted,
and you wont need the catsubcat() function any more.

Code: [Select]

<?php
if ($r['displaytitle'] == 'YES') {
if (!$_ID)  {
                                    if(
$categorySEF == 'test-cat'){
     echo '<h2 class="big">'.$link.$uri.'/'.$r['asef'].'/">'.$title.'</a></h2>';
                                       } else {
                                             echo 
'<h2 class="small">'.$link.$uri.'/'.$r['asef'].'/">'.$title.'</a></h2>';
                                        }
   } else {
                                        if(
$categorySEF == 'test-cat'){
     echo '<h2 class="big">'.$title.'</h2>';
                                        } else {
                                             echo 
'<h2 class="small">'.$title.'</h2>';
                                        }
}
}
?>


sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Re: how to select subcat in function articles?
« Reply #6 on: February 17, 2013, 09:56:33 AM »

Ha!!! That was easy; probably I need to take a few days off to clean up my mind as I use categorySEF for other stuff, but for this my mind stop working!! I donít know what I was thinking.
Thanks mosh and nukpana.
Logged