I have 6 tables, due to the different news portal, in which the layout of the main page is classified as follows.
- Where different covers are shown, with different categories, the most viewed news, the most popular news, the new news, more news, upcoming games, live games today, among others.
- The design of the portal can be seen in the following demo template, which is why the news is divided into 6 different tables.
In the following way, the detail of the news is displayed without problem.
<?php
require "app/php/require.ini.php";
include "app/php/date_es.php";
include 'themes/template/header.php';
if (isset($_GET['id'])) {
$url = $_GET['id'];
}
$stmtID = $con->prepare("SELECT id_mini_cover,cover_page,title,description,url,date_post,detail FROM mini_cover WHERE url=? limit 1");
$stmtID->bind_param("s",$url);
$stmtID->execute();
$stmtID->store_result();
$stmtID->bind_result($id_mini_cover, $cover_page, $title, $description, $url, $date_post, $detail);
if ($stmtID->fetch()) {
include 'app/themes/detail_mini_cover.ini.php';
} else {
echo "No existe noticia";
}
include 'themes/template/footer.php';
?>
Everything looks so good, even the fancy friendly URLs.
ejemplo.com/world-russia-2018/
Via .htaccess fileRewriteRule ^([a-zA-Z0-9-/]+)$ all_sport.php?id=$1
Now the problem is that I don't know how to show the detail of the other news from the other tables.
Try to create a file similar to all_sport.php
with another name all_sport_one.php
and with other query data, for the other tables, but it shows me the message that there are no news, when I access a URL of a news of that query, which does exist.
Despite having put another line to the .htaccess it didn't work.
RewriteRule ^([a-zA-Z0-9-/]+)$ all_sport_one.php?id=$1
Can you explain to me how I can show the detail of a news item taking into account the 6 different tables?
To say right now as to have an example to guide me, as I show the details of the first query as well as this second query.
And so on with the other 4 missing queries from the 6 tables.
<?php
require "app/php/require.ini.php";
include "app/php/date_es.php";
include 'themes/template/header.php';
if (isset($_GET['id'])) {
$url = $_GET['id'];
}
$stmtID = $con->prepare("SELECT id_mini_cover,cover_page,title,description,url,date_post,detail FROM mini_cover WHERE url=? limit 1");
$stmtID->bind_param("s",$url);
$stmtID->execute();
$stmtID->store_result();
$stmtID->bind_result($id_mini_cover, $cover_page, $title, $description, $url, $date_post, $detail);
if ($stmtID->fetch()) {
include 'app/themes/detail_mini_cover.ini.php';
} else {
echo "No existe noticia";
}
include 'themes/template/footer.php';
?>
Additional Information
The following code:
if (isset($_GET['id'])) {
$url = $_GET['id'];
}
Get the data from the URL, for example: world-russia-2018/
The data obtained from the URL becomes a condition for the query in WHERE url=?
, in order to reflect the details of that news, which coincides with that URL in the records.
I don't think you can have two equal rules in the same .htaccess
since they both look for the same thing, how could I know which php to redirect to?
Probably always go first (all_sport.php)
Perhaps a solution is to add something extra that allows you to distinguish one url from another.
For example
ejemplo.com/world-russia-2018/
I would take you toall_sport.php?id=world-russia-2018
While
ejemplo.com/lo-que-sea/one
I would take you toall_sport_one.php?id=lo-que-sea
It's just a possibility. Another option would be to create a distinction in the url before the id:
For the latter case, they would be something like this:
You may also find it interesting to add an additional 'generic' rule like the one you used. And that would be used in case of not entering through the 'category'. What you should check is the last rule because it 'finds anything' and if it is the first, it does not give the others an option.
So the last rule could be something like: