generate dynamic content in one page

Discussion in 'PHP' started by mol, Nov 4, 2007.

  1. #1
    Hi all..

    I am new in php and mysql,

    I have a question:

    I have an home page, there are three links : news1, new2 and news3.

    and then I have one page to display the news, display.php.

    Can I display news1,news2,news3 in display.php. So I dont need to make

    3 different page (display1.php, display2.php, display3.php) to display

    3 different content (news1, new2 and news3)

    I want to make it dynamic.


    many thanks
     
    mol, Nov 4, 2007 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    yep, one way is, it is done by declaring a parameter.

    u must have a "container" using css where you will put all those links..
    and then call for the parameters..

    <a href="display.php?parameter=1">news1</a>
    <a href="display.php?parameter=2">news2</a>
    <a href="display.php?parameter=3">news3</a>
    for example:

    display.php
    
    
    <a href="display.php?parameter=1">news1</a> 
    <a href="display.php?parameter=2">news1</a>
    <a href="display.php?parameter=3">news1</a>
    
    $parameter = $_GET['parameter'];
    
    switch($parameter) // switch statement is under the container
    {
       case 1:
           include("news1.php");
       break;
    
       case 2:
           include("news2.php");
       break;
    
       case 3:
           include("news3.php");
       break;
    }
    
    PHP:
    hope this help..
     
    bartolay13, Nov 4, 2007 IP
  3. Kallisto

    Kallisto Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think, that bartolay13's code not safety...

    
    $default = 1;
    $url[1]="news1.php";
    $url[2]="news2.php";
    $url[3]="news3.php";
    
    if(isset($_GET["page"])) 
    {
    $page=intval($_GET["page"]);
    if($page<1 or $page>count($url)) $page=1;
    if(@$url[$page]=='') $page=1;
    include($url[$page]);
    }
    include($url[$default]);
    
    
    Code (markup):
     
    Kallisto, Nov 4, 2007 IP
  4. mol

    mol Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK many thx, i'll try it
     
    mol, Nov 5, 2007 IP