Author Topic: Getting cat ID  (Read 5254 times)

0 Members and 1 Guest are viewing this topic.

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Getting cat ID
« on: April 03, 2006, 03:56:32 PM »
I have been searching for weeks a small post by Jan on how to use cat ID for some work in gallery…
unfortunately I cannot find it…  :?

I wanted to make the following loop…
So how do I make the following code correct?

============================================
$id = {cat_id};

if ($id == "2") {
include(ROOT_PATH.'some_file1.php')
}

if ($id == "3") {
include(ROOT_PATH.'some_file2.php')
}

==============================================

Thanks :D

Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
Re: Getting cat ID
« Reply #1 on: April 03, 2006, 05:35:45 PM »
$id = {cat_id};

should be like: $id = $cat_id
you can't use {cat_id} in the php file,
cause their only parsed in templates.
Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline Eagle Eye

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: Getting cat ID
« Reply #2 on: April 03, 2006, 05:43:31 PM »
$id = {cat_id};

should be like: $id = $cat_id
you can't use {cat_id} in the php file,
cause their only parsed in templates.

Thanks, i know that we cannot use "{cat_id}" in php file, what i meanto ask was what is the correct synatax to be placed so that i can get the same info as {cat_id} would give in templates... thanks ;) i will check it out...

Offline IcEcReaM

  • Hero Member
  • *****
  • Posts: 714
    • View Profile
    • My little Testboard
Re: Getting cat ID
« Reply #3 on: April 03, 2006, 05:59:43 PM »
ah i forget.
if you got a lot of different ids:
instead of:

if ($id == "2") {
include(ROOT_PATH.'some_file1.php')
}

if ($id == "3") {
include(ROOT_PATH.'some_file2.php')
}

you can use switch.

for example:
switch($id) {
 case 3:
    include(ROOT_PATH.'some_file2.php');
    break;
 case 4:
 ....

}
Coding is a everlasting competition between programmers who tries to write larger, better and idiot-safe programs and the universe producing larger and stupider idiots...
...so far the universe won
bump

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Getting cat ID
« Reply #4 on: April 04, 2006, 12:36:52 AM »
Or another solution:
Code: [Select]
if (in_array($cat_id, array(2,3,4,5,10,8)))
{
  include(ROOT_PATH.'some_file'.$cat_id.'.php');
}
Only usefull if you want to have independed "some_fileXX.php" for each category
and if you want to "share" one file for more then one category:
Code: [Select]
$ids = array( //first number is category id, second number is file number
  2 => 1,
  3 => 2,
  4 => 1,
  5 => 3,
  10 => 4,
  8 => 2,
);
if (isset($ids[$cat_id]))
{
  include(ROOT_PATH.'some_file'.$ids[$cat_id].'.php');
}
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)