douji9518 2017-05-24 15:31
浏览 42

php中的动态网站

i have created a generic template which should display the content of the parameter being passed in the URL by fetching details from the database.

Ex.
Home page: index.php
Template: Pages.php
link displayed on Home page: "This is fetched from Database"
when clicked it should navigate to: Pages.php/This is fetched from Database (this is the parameter passed to the database to get the content)

This is working properly but when the i click Home (index.php) in Pages.php/This is fetched from Database the same is being treated as Pages.php/index.php but it should go to index.php directly.

I have used htaccess for rewriting the url but it didnt workout.

Basically i am building a dynamic website and my question is how can i effectively use the generic template concept for achieving the dynamic website?

The code i used for getting this Pages.php/This is fetched from Database

<?php    
$mysqli = new mysqli("localhost", "root", "12345", "dbname");    
$uri = $_SERVER["REQUEST_URI"];    
$uri = $uri[4];    
$result = $mysqli->query("SELECT Title FROM Posts where Title = $uri");    
echo "<a href = '"./pages.php/{$row["Title"]}."' alt = "">{$row["Title"]}
</a>";    
?> 
  • 写回答

2条回答 默认 最新

  • douhu1990 2017-05-24 15:38
    关注

    You can do some search on php design patterns to have better idea about what you try to achieve .

    Here is somewhere you can start from :

    simple-php-mvc-beginners-tutorial

    For your code ,

    $uri = $uri[4]; 
    

    $uri is a string not an array , so the above line will only get the character on the 4th position , try to remove that line and test .

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据