簡體   English   中英

通過多個表在PHP和Mysql中動態創建鏈接

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

我是PHP的初學者。 我已經為網站創建了搜索欄。 但是我不知道如何為結果創建動態鏈接。 我能夠從大約4-5個表中獲取數據。 如何為4個表創建動態鏈接(mysql)。

提前致謝。

對此,我們將給予任何幫助。

$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;
}

您的文章URL應該如下所示:“ http://websiteurl.com/category(news,articles)/123(product-id)/short-title-for-seo ”。 建議您在顯示內容時,將所選材料的ID和類別作為主要過濾器。 要獲取表名(或將表名轉換為類別別名),可以執行以下操作:從table1中選擇'table1'作為tableName

首先要知道的是,如果要顯示數據庫中的動態數據,則必須存儲一個垂直的$result['title']的URL,該URL必須包裹在定位標記<a>周圍。 例如: <?php echo '<a href='.$result['url'].'><h3>'.$result['title'].'</h3></a>';?>

或者可以對網址的某些部分進行硬編碼,並在網址的最后一部分中指向標題的ID。 例如: <?php echo '<a href=http://www.your-domain/content/index.php?id='.$result['id'].'><h3>'.$result['title'].'</h3></a>';

稍后,您必須創建一個新頁面,其中$_GET是來自url的條目,並顯示描述或完整詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM