Been struggling with this problem for a while now and I just can't het my brain to understand it.
I have a very simple website where I can add items in a database. There is a list on index.php where the list is displayed and each item needs a url that directs to a "more information" page.
The "more information" page has to be a dynamic one as there are a lot of items and these items can be added or deletend.
What my code for this section looks like at the moment:
$result_set = mysql_query("SELECT id, name FROM items WHERE id = $item");
while ($item = mysql_fetch_row($result_set)) {
$name = $item['name'];
echo "<a href=\"/items/".$item['1'].".html\">$name</a>";
This results in a link if item 1 = wrench ../items/wrench.html.
But this page obviously doesn't excist. How can I get this to work?
You can't have one html page for each item if the items are dynamically added But you can do it this way
echo '<a href="/items/more_information.php?item_id='.$item['1'].' ">$name</a>';
This way you have only one page who receive as a GET parameter the id of the item you want the description. In the page of more_information.php you just display a text corresponding to the id you received.
use .htaccess for this. you can add this code
RewriteEngine On
RewriteRule ^items/(.+)$ items.php?page=$1
In your items.php use $items=$_GET[page]; so you can read what is in url after items/
This is a link where you can find more about RewriteRule's http://httpd.apache.org/docs/current/rewrite/intro.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.