douludi8413 2013-08-09 01:27
浏览 33
已采纳

如何使用数据库值创建4个动态页面[关闭]

I currently have 4 pages(about, interviews, ask a q, contact) per people and I have 250+ people and it takes a long time to create a new people to the site

What is the best way to have just 4 pages(about, interview, ask a q, contact) that loops through the database people and creates their pages on the fly when the user requests them?

here's an example of a person on the site http://starsQA.com/aaron-cole

I'm thinking of using $_GET variables from the database and changing the url using .htaccess rewriting, but I have no clue how to do this or if it's even possible

the site uses html, php, mysql and oop

What is the best way to achieve this?

I have added this:

<?php session_start();
error_reporting(E_ALL ^ E_NOTICE);
include("db_conn.php");
$qry_string = "select * from stars INNER JOIN roles ON roles.starID = stars.starID where stars.starID = ?";
$prep = $pdo_conn->prepare($qry_string);  
$prep->execute(array($_GET['id']));
$result = $prep->fetch(PDO::FETCH_ASSOC);
$pieces = explode(" ", $result['starName']);
$gender = "him"; 
?> 

and now if you use http://www.starsqa.com/about?id=52 you can aaron cole and id=6 lindsey mckeon

How to figure out how to change the url to http://www.starsqa.com/about?id=52 to http://starsQA.com/aaron-cole-about

tried this, but i didn't seem to work: sending a user from starsQA.com/aaron-cole-about to starsQA.com/about?id=52) :

 RewriteCond %{QUERY_STRING} ^$
 RewriteRule ^/aaron-cole-about$ /about?id=52 [L]

here's my current .htaccess file

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.php$
RewriteRule ^(.*)$ $1.php [L,QSA]

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/aaron-cole-about$ /about?id=52 [L]

Is it possible that the user entered in aaron-cole-about and behind the scenes it uses about?id=52 but still shows the user aaron-cole-about ???

  • 写回答

1条回答 默认 最新

  • douciwang6819 2013-08-09 02:14
    关注

    Even though it cannot be termed a strict duplicate, does this answer help you get an idea.

    how do i create a unique php page for each row in a mysql database

    Both answers together would allow you to create all the pages. Though you need four pages per record, it should not be very different to loop through them.

    then rules similar to the one below

    RewriteRule ^about/([^/]+)_([^?/]+).html /about.php?personid=$2

    The first part ^about says anything with url http://yoursite.com/about/ should use this rule. In an url like http://yoursite.com/about/xxxx_1234.html the first part ([^/]+) and ([^?/]+) indicate that the it would split the actual url into xxxx 1234 and html then the rule would redirect the user to about to about.php?personid=1234

    A combination of these two should do for you. Hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式