dongxiji0687 2012-01-31 17:53
浏览 64
已采纳

如何根据点击的链接以不同方式填充1个php页面?

Sorry for this question.

Basically I have a page where I have it automatically sorting through categories etc and each block (img and 1 or 2 details) has a link (which takes to a Static Profile page). I also have a database created that with another page that is used to populate it.

Now I could create a page (html or php) for each but this is not what I want as I do not want 100 pages of the same thing/layout just different data and images.

I want to use the same layout on e.g. single.php - but populate it differently depending on which link the user clicked.

I seem to understand the logic I just dont understand how to do it. It's obviously pulling the data from each database entry depending on the one clicked.

Very sorry to annoy you all as I am sure it is easy but I just can't get my head around it.

Thanks for any help you can provide.

Example.

index.php <- which I have working fine. User can get to the desired link using filters (name, category, etc)

single.php <- I want this to be the 1 php page that is populated with different data depending on which link the user clicked. So no.1 is clicked and single.php displays the data for profile1, no.2 is clicked and single.php displays the data for profile2 etc.

The data I am referring to will be static text with 1 or 2 a href links (standard) and also some images.

I know it is meant to be something like this single.php?=somethinghere but I am not sure.

If anyone can help I would be very appreciative.

***EDITED BELOW***

So would I do the following then? As I am trying to pull the data from the database to populate the single.php page.

`if($_GET['link']=='companyname1'){
    //print company1 details on single.php page
    echo '<div>info on companyname1 from database</div>';
    echo '<otherdiv>other info on companyname1 from database</div>';

}elseif($_GET['link']=='companyname2'){
    //print company2 details on single.php page
    echo '<div>info on companyname2 from database</div>';
    echo '<otherdiv>other info on companyname1 from database</div>';

}else{
    //print main index
}`
  • 写回答

3条回答 默认 最新

  • dooo61733 2012-01-31 18:00
    关注

    make your links similar to this

    index.php?link=category
    

    then in the php

    if($_GET['link']=='category'){
        //print category page
    
    }elseif($_GET['link']=='name'){
        //print name page
    
    }else{
        //print main index
    }
    

    edit: here is a decent article. $_POST is the method you use when the variables are passed using a form. $_GET is whats used when people click links or type directly in the url bar.

    http://mrarrowhead.com/index.php?page=php_passing_variables.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)