Hashtag和分页php不显示查询

时间:2016-11-09 18:57:32

标签: php mysql pagination hashtag

首先是在mysql列(关键字)中搜索特定文章的标签词的的hashtag脚本,但是我在显示 $istorielist 的结果时遇到了问题没有显示任何行

$stmt = $con->prepare("SELECT id, titlu, link, poza, alt, keywords, 
linknews FROM stiinta WHERE   approved='1' AND  replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE  '%$keyword%' UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM travel WHERE   approved='1' AND  replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE  '%$keyword%' UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM stiinta WHERE   approved='1' AND  replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE  '%$keyword%' UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM natura WHERE   approved='1' AND  replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE  '%$keyword%' UNION SELECT id, titlu, link, poza, alt, keywords, linknews FROM lifestyle WHERE   approved='1' AND  replace(replace(replace(keywords, ',', ''), '-', ''), ' ', '') LIKE  '%$keyword%' LIMIT 3");
$stmt->execute();
$stmt->bind_result($id, $titluKEY, $linkKEY, $pozaKEY, $altKEY, $keywordKEY, $linknewsKEY);//variabla pe care o vrei inlocuita prin bind_Result in loc de get_Result
$stiintalist = '';
while ($stmt->fetch())    {
    $id;
    $titluKEY;
    $linkKEY;
    $pozaKEY;
    $altKEY; 
    $keywordKEY;
    $linknewsKEY;   // faci acelasi lucru fara $row trb sa fie in concordanta cu ceea ce este in SELECT column pentretu teste a href="/page-stiinta.php?pid='.$linkKEY.'"
    $stiintalist .= '<div id="articol-content-more"><a href="/'.$linknewsKEY.'"><img src="/images/'.$pozaKEY.'.jpg"class="articol-content-more-image" alt="'.$altKEY.'"><p class="articol-content-more-title">'.$titluKEY.'</p></a><span><a class="articol-content-more-afla" href="/'.$linknewsKEY.'">Citește mai multe</a></span><span class="articol-content-more-fl"><div class="fb-share-button" data-layout="button_count" data-href="http://esticurios.ro/'.$linknewsKEY.'"></div></span></div>';        
echo $stiintalist;//the results doesnot show any query even if i have others records with the some value from the column (keywords)
    }

其次我在显示单词的所有查询时遇到问题...例如,如果我有50个包含标签词的查询,那么分页(etichete.php)显示我的唯一3页每个10个查询()所以只显示30个而不是全部50个。

其他问题我有,我无法弄清楚如何制作标签内容-例如(前10名)没有显示所有查询的单词如果我有标签字(top或top_10)正在工作但是上面提到的问题

,则列(titlu)中有top或10
function convertHashtags($str){
       $regex = "/#+([0-9a-zA-Z_-]+)/";
       $str = preg_replace($regex, '<a id="tags" href="../etichete.php?tag=$1">$0</a>', $str);//id="tags" CSS custome
       return($str);
       }
   $string = $keyword;
   $string = convertHashtags($string);
   echo $string; 

和etichete.php

if(isset($_GET['tag'])){
    $tag = preg_replace('#[^a-z0-9_]#i', '', $_GET['tag']);#+([0-9a-zA-Z_-]+)/ [^a-z0-9_]
    // $tag is now santized and ready for database queries here
    $fulltag = "<h3>Articole despre ".$tag."</h3><br>";
    echo $fulltag;

// this first query is just to get the
$sql = "SELECT COUNT(id) FROM istorie WHERE approved='1'  UNION  SELECT COUNT(id) FROM lifestyle WHERE approved='1'  UNION  SELECT COUNT(id) FROM stiinta WHERE approved='1' UNION  SELECT COUNT(id) FROM travel WHERE approved='1' UNION  SELECT COUNT(id) FROM natura WHERE approved='1'";
$query = mysqli_query($db_conx_tag, $sql);
$row = mysqli_fetch_row($query);
//here we have the total row count
$rows = $row[0];
// this is the number of results we want displayed per page cate query(interogari) sa afisieze pe pagina
$page_rows = 10;
// this tells us the page number of our last page
$last = ceil($rows/$page_rows);
// this makes sure $last cannot be less than 1
if($last < 1){
    $last = 1;
}
//establishes the $pagenumb variable
$pagenum = 1;
//get pagenumber from url vars if is present, else it is = 1
if(!empty($_GET['pn'])){
    $pagenum = preg_replace('#[^0-9]#', '',  $_GET['pn']);
}
// this makes sure the page number isn't below 1 or more than our $last page
if ($pagenum < 1) {
    $pagenum = 1;
} else if ($pagenum > $last) {
    $pagenum = $last;
}
// this set the range of rows to query for the chosen $pagenum
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
// this is your query again is t -- ce sa fie in tabel si dupa ce fie ales daca e dupa data sau dupa id.. modific si obtin cum
    $sql = "SELECT id, titlu, descriere, data, linknews, poza, alt FROM istorie WHERE titlu  LIKE '%$tag%' UNION SELECT id, titlu, descriere, data, linknews, poza, alt FROM lifestyle WHERE titlu LIKE '%$tag%' UNION SELECT id, titlu, descriere, data, linknews, poza, alt FROM natura WHERE titlu LIKE '%$tag%' UNION SELECT id, titlu, descriere, data, linknews, poza, alt FROM travel WHERE titlu LIKE '%$tag%' UNION SELECT id, titlu, descriere, data, linknews, poza, alt FROM stiinta WHERE titlu LIKE '%$tag%' ORDER BY data DESC $limit";
    $query = mysqli_query($db_conx_tag, $sql); 
    echo mysqli_error($db_conx_tag);
// this show the user what page they are on, and the total number of page
$textline1 = "Număr total de articole (<b>$rows</b>)";
$textline2 = "Pagina a <b>$pagenum</b> din <b>$last</b>";
// establish the $paginationCtrls variabls
$paginationCtrls = '';
// if the is more than 1 worth of resurls
if($last != 1){
    /* first we check if we are on page one. if we are then we don't need a link to the previous page or the first page so we do nothing, if we aren't then we generate links to the first page and to the previous page. */
    if ($pagenum > 1) {
        $previous = $pagenum - 1;
        $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?tag='.$tag.'&amp;pn='.$previous.'">Anteriora</a> &nbsp; &nbsp; ';
        // render clickable number links that should apeer on adica ce arata ca pagina daca e pe 6 e-4 deci arata 3
        for($i = $pagenum-3; $i < $pagenum; $i++){
            if($i > 0){
                $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?tag='.$tag.'&amp;pn='.$i.'">'.$i.'</a> &nbsp; ';
            }
        }
    }
    // render the target page number, but without it beging
    $paginationCtrls .= ''.$pagenum.' &nbsp; ';
    // render clicktable number links that should apeer on the right daca e pe 9 sa nu ii arata si sunt doar 10 pagini in total sa iia rate 12 si asa mai departe
    for($i = $pagenum+1; $i <= $last; $i++){
        $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?tag='.$tag.'&amp;pn='.$i.'">'.$i.'</a> &nbsp; ';
        if($i >=$pagenum+4){
            break;
        }
    }
    // la fel ca mai sus la randul 42 cu previous
    if ($pagenum > 1) {
        $next = $pagenum + 1;
        $paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?tag='.$tag.'&amp;pn='.$next.'">Urmatoarea</a> &nbsp; &nbsp; ';
        // render clickable number links that should apeer on adica ce arata ca pagina daca e pe 6 e-4 deci arata 3
    }   
}
    $tagsearch = '';  
    while($row = mysqli_fetch_array($query)){
        $id = $row["id"];
        $titlu = $row["titlu"];
        $data = $row["data"];
        $linknews = $row["linknews"];
        $descriere = $row["descriere"];
        $poza = $row["poza"];
        $alt = $row["alt"];
        $tagsearch  .= '<div class="articol-small"><a href="/'.$linknews.'"><img src="/images/'.$poza.'.jpg"class="articol-small-image" alt="'.$alt.'"><h2 class="articol-title">'.$titlu.'</h2></a><div class="posted-date">'.$data.'</div><p class="articol-details">'.$descriere.'</p><a href="/'.$linknews.'" class="read-more">Citeste mai multe</a></div><br>';
    }
}

我知道我做了一个很大的帖子,但是不能解决这些问题超过1周的花费....

0 个答案:

没有答案