如何通过hashtag变量选择查询?

时间:2016-07-09 17:06:33

标签: php mysql hashtag

嘿,我想通过一个hashtag系统选择一个查询,我制作了一个hashtag系统,但是我不知道如何制作SELECT语句,显示所有查询哪些单词是带有标签词的一些

**exemple.php**
   <?php
   function convertHashtags($str){
       $regex = "/#+([a-zA-Z0-9_]+)/";
       $str = preg_replace($regex, '<a href="../hashtag.php?tag=$1">$0</a>', $str);
       return($str);
       }
   $string = "My first #hashtag #word show";
   $string = convertHashtags($string);
   echo $string;  
    ?>

和hashtag.php

<?php
//conectare
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "esticuri_utile";

//create connection to mysql
$db_conx_noutati = mysqli_connect($servername, $username, $password, $dbname);
$db_conx_noutati->set_charset('utf8');// pentru diacritice
if(!$db_conx_noutati){
 die("Connection failed: ". mysqli_connect_error());
}

if(isset($_GET["tag"])){
    $tag = preg_replace('#[^a-z0-9_]#i', '', $_GET["tag"]);
    // $tag is now santized and ready for database queries here
    $fulltag = "#".$tag;
    echo $fulltag;
    }


    $sql = "SELECT id, data, linknews, poza, alt, titlu FROM istorie UNION SELECT id, titlu, data, linknews, poza, alt, titlu FROM lifestyle LIKE '%$tag%'";
    $query = mysqli_query($db_conx_noutati, $sql); 
    $noutatiupdate = '';  
    while($row = mysqli_fetch_array($query)){
        $id = $row["id"];
        $titlu = $row["titlu"];
        $data = $row["data"];
        $linknews = $row["linknews"];
        $poza = $row["poza"];
        $alt = $row["alt"];
        $noutatiupdate .= '<article><a href="/'.$linknews.'"><h2 align="center"><b>'.$titlu.'</b></h2><img src="/images/'.$poza.'.jpg"class="imagini-noutati"alt="'.$alt.'"></a><a class="read-more-noutati" href="/'.$linknews.'">Citește mai multe...</a><span class="posted-date-noutati">'.$data.'</span></article><br>';
}
?>  

             <?php echo $noutatiupdate;?> 
             <?php mysqli_close($db_conx_noutati);?> 

它给了我一个错误

  

警告:mysqli_fetch_array()要求参数1为mysqli_result,布尔值在第29行的C:\ Program Files \ EasyPHP-DevServer-14.1VC11 \ data \ localweb \ hashtag.php中给出

0 个答案:

没有答案