dp152153 2017-11-03 10:14
浏览 25

根据网址从数据库中获取内容

I am trying to get the content from the database depending on the url. Lets say that you are on index.php then I want to get the content from the database with the entity page. My database looks like this:

|id | page | header | content | feature | footer |
|01 |index | header | content | feature | footer |

It is not the whole as it is a project that I can't show all of it, so I put in just dummy data in it here.

The config.php:

<?php
$url = $_SERVER['REQUEST_URI'];
$dbhost = "dummyhost";
$dbuser = "dummyuser";
$dbpass = "";
$dbname = "dummy";

$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

if(!$conn){
  die("ERROR");
}

$index = mysqli_query($conn, "SELECT FROM pages WHERE page LIKE '".$url."%');
$indexRow = mysqli_fetch_assoc($index);
$indexHeader = $indexRow['header'];
$indexContent = $indexRow['content'];
$indexFooter = $indexRow['footer'];
$indexfeature = $indexRow['feature'];

How can I do it? I know that I can use $_GET to get some variables from the adress, but in this case I am not using any variables to go to another site. Can I still use that or am I on the right track?

  • 写回答

1条回答 默认 最新

  • dpbyr64224 2017-11-03 13:44
    关注

    EDIT: As the question says NOT to use the query string.

    I am trying to get the content from the database depending on the url. Lets say that you are on index.php then I want to get the content from the database with the entity page.

    You can get the filename called by

    $path = parse_url($url, PHP_URL_PATH);
    $path = explode('&',$path);
    $filename = substr($path[0], -4); // removing '.php'
    

    You can create your SQL accordingly now and use the filename.

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助