简体   繁体   English

将多个 php 搜索结果输出到不同的页面?

[英]outputting multiple php search results to a different page?

I am trying to output the search results in a different php page with an input and submit button.我正在尝试使用输入和提交按钮在不同的 php 页面中输出搜索结果。 It does work but it only displays one result at a time because theres only one placeholder for all the results, is there any way to output multiple relevant results and give each result its own placeholder?它确实有效,但一次只显示一个结果,因为所有结果只有一个占位符,有没有办法输出多个相关结果并为每个结果赋予自己的占位符?

for example i have three names in the database as follows, searching for win10 should result in two results, but it only outputs the first one.例如我在数据库中有如下三个名称,搜索win10应该会产生两个结果,但它只输出第一个。

win7-haystack
win10-iceland
win10-road

heres the search php:继承人搜索php:

<?php
$arr = [];
$searchq = "%{$_POST['search-input']}%";
$stmt = $pdo->prepare("SELECT wallname FROM walldb WHERE wallname LIKE ?");
$stmt->execute([$searchq]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  $arr[] = $row;
}
foreach($arr as $value){
    $val = implode('', $value);
    //echo ($val);
    //echo("<br><br>");
  }
$stmt = $pdo->prepare('SELECT * FROM walldb WHERE wallname = :val');
$stmt->bindParam(':val', $val);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $mlink = $row['mainlink'];
    $tlink = $row['thumbnail'];
    $dlink = $row['download'];
    $info = $row['info'];
  }
  /*echo ($mlink);
  echo("<br>");
  echo ($tlink);
  echo("<br>");
  echo ($dlink);
  echo("<br>");
  echo ($info);  */
  $final = ("<li><a href="."$mlink"."data-lightbox='wallpaper1'><img class='searchicon' src="."$tlink"."></a><span>"."$val"."</span><img class='searchbutton1 s1'
  src='/images/info.png'><a id='wall1.download' href="."$dlink"."><img class='searchbutton2' src='/images/download.png'></a>
<ul class='searchmenu menu1'>
  <p>"."$info"."</p>
</ul>
</li>");
?>

heres the result php:继承人的结果php:

    <form action= "" method= "post">
      <a href="#"><img id="glass" src="/images/search.png" type= "submit" 
    name="submit-search"></a><input id="search" name="search-input" 
    type="search" placeholder="Search By Name" autocomplete="off"><a 
    href="#"><img id="cancle" src="/images/cancle.png"></a>
   </form>
     <section id="result"><?php echo $final; ?></section>

You are going through what should be the same set of query results twice, and both times throwing away everything except the values from the last iteration.您将经历两次应该是同一组查询结果的内容,并且两次都丢弃了除上次迭代中的值之外的所有内容。 Try something like this:尝试这样的事情:

$arr = [];
$searchq = "%{$_POST['search-input']}%";
$stmt = $pdo->prepare('SELECT * FROM walldb WHERE wallname LIKE ?');
$stmt->execute([$searchq]);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $mlink = $row['mainlink'];
    $tlink = $row['thumbnail'];
    $dlink = $row['download'];
    $info = $row['info'];

    // Generate the desired per-row output, saving it in an array for later use.
    // Not clear what that should be, so this is a guess. Modify as needed.
    $arr[] = '<li>' . $mlink . '<br>' . $tlink . '<br>' . $dlink . '<br>' . $info . '</li>';
}

$final = '<ul>' . implode('', $arr) . '</ul>';

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

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