我知道这个问题在很多地方都被问过,但我想要达到的目标有点不同。
设想:
我有一个 /hotel/index.php 页面,该页面使用变量“id”从 MySQL 数据库中提取酒店数据。
我想要实现的是例如 /hotel/index.php?id=1 应该显示为 /hotel/hotelname/
这是我的 index.php 的样子:
<?php
$dbhost = something;
$dbuser = somethingmore;
$dbpass = alotmore;
$hid = $_GET["id"];
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT * FROM hotel where id = .$hid';
mysql_select_db('h_db');
$retval = mysql_query("SELECT * FROM hotel WHERE id='". mysql_real_escape_string( $hid ) ."'", >$conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
if($row['inventory_source']="T") // Check inventory source
{
$hotelid = $row['hotelid_t'];
}
else
{
$hotelid = $row['hotelid_b'];
}
$hotelname = $row['hotel_name'];
$thumbnail = $row['thumbnail'];
$hoteladdress = $row['hotel_address_full'];
$cityname = $row['city'];
$cityid = $row['cityid'];
$country = $row['country_name'];
$propertydesc = $row['property_description'];
$amenities = $row['xmlamenities'];
$checkin = $row['checkin'];
$checkout = $row['checkout'];
$petsallowed = $row['pets_allowed'];
$guestrating = $row['overall_rating'];
$star = $row['star_rating'];
$roomcount = $row['room_count'];
}
我知道这可以使用 mod_rewrite 来实现。但我不知道该怎么做。专业人士的任何帮助将不胜感激。