I am beginner in PHP. I have created a search bar for a website. But i have no clue how to create a dynamic link for the results. I am able to fetch the data from around 4-5 tables. how to create a dynamic link for 4 tables(mysql).
Thanks in advance.
Any help on this is highly appreciated.
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$sql = mysql_query(
"SELECT id,title,brief,description,time,image1
FROM news
WHERE (`brief` LIKE '%".$query."%') OR (`description` LIKE '%".$query."%')
UNION
SELECT id,title,brief,description,time,image1
FROM articles
WHERE (`brief` LIKE '%".$query."%') OR (`description` LIKE '%".$query."%')
UNION
SELECT id,title,brief,description,time,image1
FROM interview
WHERE (`brief` LIKE '%".$query."%') OR (`description` LIKE '%".$query."%')
UNION
SELECT id,title,NULL,description,NULL,NULL
FROM academy
WHERE (`title` LIKE '%".$query."%') OR (`description` LIKE '%".$query."%')
ORDER BY id DESC ")
or die(mysql_error());
if(mysql_num_rows($sql) > 0){
while($results = mysql_fetch_array($sql)){
echo "<p><h3>".$results['title']."</h3><br>".$results['brief']."".$results['time']."</p>";
}
} else {
echo "No Results Found";
}
} else {
echo "Minimum length is ".$min_length;
}
Your article URL should look like this: " http://websiteurl.com/category(news,articles)/123(product-id)/short-title-for-seo ". I'd recommand you to put the id of the selected material and the category as the main filter when showing the content. To get the table name (or to convert the table name to a category alias) you can do something like this: SELECT 'table1' as tableName from table1
First thing to know is if you want to display a dynamic data from database, you have to store a url for a perticular $result['title']
which has to be wrapped around an anchor tag <a>
. For example: <?php echo '<a href='.$result['url'].'><h3>'.$result['title'].'</h3></a>';?>
Or some part of the url can be hard coded and point to the title's id in the last part of the url. For example: <?php echo '<a href=http://www.your-domain/content/index.php?id='.$result['id'].'><h3>'.$result['title'].'</h3></a>';
Later you must create a new page which $_GET
s the slug from the url and display the description or full details.
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.