I have a site which has 200+ sub categories. I want every single sub category to display a unique description I dont want to use 200+ PHP files and include them. Is there a way I can acheive this using single php file? help appreciated dave
you can if you have a mySQL database ..... Just add the different descriptions as their own records and pull the record asked for. If you have an example of what you are loking for we can try to modify the code for you.
Hi Mokimofiki, Thanks for your response. I dont want to mess with the database really and looking for an alternative. This is what I have so far <?php if($xcatid==2) { echo("This is description 2."); } if($xcatid==4) { echo("This is description 4."); } if($xcatid==5) { echo("This is description 5."); } ?> does this make sense? dave
switch (variable) { case variables value what to do break; Example: switch ($xcatid) { case 2: echo("This is description 2."); break; case 4: echo("This is description 4."); break; case 5: echo("This is description 5."); break; default invalid category selected break; }
Use an array... $Desc = array(); function AddDesc($ID,$DescTxt) { global $Desc; $Desc[$ID]=$DescTxt; } function GetDesc($ID) { global $Desc; return $Desc[$ID]; } AddDesc(1,'Desc 1'); AddDesc(2,'Desc 2'); If you would like more help, message me.
Hi, Thanks, is this how am suppose to do it? <?php switch ($xcatid) { case "$xcatid==2": echo("This is description 2."); break; case "$xcatid==4": echo("This is description 4."); break; case "$xcatid==5": echo("This is description 5."); break; default invalid category selected break; } ?> dave
The method I proved is much more refined and less code...Meaning PHP will perform faster(caching if you have it) Arrays help in the case of calling the information in other places...Just follow what I gave you.
Hi Thanks for the info, the problem is i m not a full fledged coder. It will help a lot if u can give an example with my variables. dave
$Desc = array(); function AddDesc($ID,$DescTxt) { global $Desc; $Desc[$ID]=$DescTxt; } function GetDesc($ID) { global $Desc; return $Desc[$ID]; } /* Keep adding on */ AddDesc(1,'This is for page one.'); AddDesc(2,'This is for page two'); AddDesc(3,'This is for page three'); PHP: Then, where ever you want the text displayed use: echo GetDesc($xcatid); PHP:
Hey NatalicWolf, This works like a charm. Thank you so much. I need some more help on this, if you can Under every category I have lot of sub categories ($xsubcatid) and i don't want them to inherit the main category description($xcatid), instead want them to have their own unique description. will you be able to help me on this? cheers dave
You can echo anything you want in PHP. example: echo "<h1>Description 1</h1><br>"; echo "Description category 1<br><br>"; echo "<b><i><u>nanner nanner</u></i><b>"; etc