简体   繁体   English

通过多个表在PHP和Mysql中动态创建链接

[英]Dynamic link creation in PHP and Mysql from more than one table

I am beginner in PHP. 我是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. 我能够从大约4-5个表中获取数据。 how to create a dynamic link for 4 tables(mysql). 如何为4个表创建动态链接(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 ". 您的文章URL应该如下所示:“ 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. 建议您在显示内容时,将所选材料的ID和类别作为主要过滤器。 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 要获取表名(或将表名转换为类别别名),可以执行以下操作:从table1中选择'table1'作为tableName

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> . 首先要知道的是,如果要显示数据库中的动态数据,则必须存储一个垂直的$result['title']的URL,该URL必须包裹在定位标记<a>周围。 For example: <?php echo '<a href='.$result['url'].'><h3>'.$result['title'].'</h3></a>';?> 例如: <?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. 或者可以对网址的某些部分进行硬编码,并在网址的最后一部分中指向标题的ID。 For example: <?php echo '<a href=http://www.your-domain/content/index.php?id='.$result['id'].'><h3>'.$result['title'].'</h3></a>'; 例如: <?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. 稍后,您必须创建一个新页面,其中$_GET是来自url的条目,并显示描述或完整详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM