Display multiple messages using one php file. how?

Discussion in 'PHP' started by niravdave, May 20, 2009.

  1. #1
    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
     
    niravdave, May 20, 2009 IP
  2. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #2
    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.
     
    mokimofiki, May 20, 2009 IP
  3. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #3
    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
     
    niravdave, May 20, 2009 IP
  4. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #4
    picouli, May 20, 2009 IP
  5. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #5
    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;
    }
     
    mokimofiki, May 20, 2009 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.

     
    NatalicWolf, May 20, 2009 IP
  7. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #7
    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

     
    niravdave, May 20, 2009 IP
  8. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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.
     
    NatalicWolf, May 20, 2009 IP
  9. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #9
    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

     
    niravdave, May 20, 2009 IP
  10. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #10
    
    
    $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:
     
    NatalicWolf, May 20, 2009 IP
  11. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #11
    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


     
    niravdave, May 20, 2009 IP
  12. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Message me on a messenger and we can work together.

     
    NatalicWolf, May 20, 2009 IP
  13. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #13
    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
     
    ezprint2008, May 21, 2009 IP
  14. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #14
    Thanks guys.

    All sorted. Appreciate all your help. specially NatalicWolf.

    cheers
    dave
     
    niravdave, May 27, 2009 IP
  15. niravdave

    niravdave Active Member

    Messages:
    675
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    88
    #15
    Hi NatalicWolf,

    I have added you on yahoo messenger. I need further help.

    Thanks man
    dave

     
    niravdave, May 31, 2009 IP