简体   繁体   English

如何分离搜索栏中的结果并将其组合在一起?

[英]How to separate result in search bar and group it together?

I've created search bar which is to search author with journal title.我创建了搜索栏,用于搜索具有期刊标题的作者。 The data is imported from CSV and it is stored in comma value for the author column.数据从 CSV 导入,并存储在作者列的逗号值中。 This is my database: MySQL database这是我的数据库: MySQL 数据库

When i search 'knowledge management' the result i get is this:当我搜索“知识管理”时,我得到的结果是:

Search Bar result搜索栏结果

How can i seperate the authors(='%$keyword%' or most likely as '%$keyword%') and grouped the titles?我如何分隔作者(='%$keyword%' 或最有可能为'%$keyword%')并将标题分组?

This is what i have tried:这是我尝试过的:

     <?php
          if(ISSET($_POST['search'])){
        $keyword = $_POST['keyword'];

     ?>

    <div>

     <h2> Result for <?php echo $keyword?></h2>

   <?php

    require 'conn.php';
    $query = mysqli_query($conn, "SELECT  author_name, GROUP_CONCAT(title)grouped_title , 
    count(*) cnt FROM `blog` 
    WHERE `author_name` LIKE '%$keyword%'  GROUP BY author_name ") 
    or die(mysqli_error());
    $result_count = mysqli_num_rows($query);
    echo '<br /><div class="right"><b><u>'.$result_count.'</u></b> results found</div>';
    while($fetch = mysqli_fetch_array($query))
    {

        
    ?>




   <hr style="border-top:4px dotted #ccc;"/>

   <div style="word-wrap:break-word;">

    <h4><?php echo $fetch['author_name']?></h4>     

    <a href="get_blog.php?author_name=<?php echo $fetch['author_name']?>"> 
   <p><?php echo $fetch['grouped_title']?></p></a>

    <hr style=""/>


    <?php


        }
     ?>
   </div>
    <?php
    }
  ?>`

There are many ways to separate the code, including: explode()代码分离的方法有很多,包括:explode()

simple example:简单的例子:

$str = "Hello,world"; 
$rechange = (explode(",", $str)); echo
$rechange[0];

If I do not understand the problem, clarify the question, or if you encounter a problem如果我不理解问题,请澄清问题,或者如果您遇到问题

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

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