我的页面上有一个搜索表单,可以从数据库中的表中搜索记录。我想显示每个查询给我们多少个结果。所有这些都是用codeigniter编写的。
我在那页上的所有代码:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index() {
$data['title'] = "Welcome | randomsite";
$data['html'] = "";
if($this->input->post()) {
$uq = $this->security->xss_clean($this->input->post('query'));
if(trim($uq) != "") {
$searchBy = $this->security->xss_clean($this->input->post('searchBy'));
$searchByJSON = json_encode(array(1 => "Email", 2 => "Username", 3 => "IP", 4 => "FullName", 5 => "Phone"), JSON_FORCE_OBJECT);
if(isset(json_decode($searchByJSON)->$searchBy)) {
$start = microtime(true);
$this->db->from('Databases');
$rs = $this->db->get()->result();
$end = microtime(true);
$data['html'] .= "Search completed in: " . ($end - $start) . " seconds.<p></p>";
foreach($rs as $row) {
$this->db->distinct();
$this->db->select('Username, Password, Email, FullName, IP, Phone, salt');
$this->db->from('Accounts');
$this->db->where(json_decode($searchByJSON)->$searchBy, $uq);
$this->db->where('DatabaseID', $row->ID);
$query = $this->db->get();
if($query->num_rows() > 0) {
if($searchBy == 5 && $query->row()->Phone == 0) {
break;
}
$resultsHTML = "";
foreach($query->result() as $qr) {
$resultsHTML .= "<div class='card-block-results' style='table-layout:fixed; word-wrap:break-word;'><table class='table table-hover' style='font-size:13px;'>";
foreach($qr as $key => $value) {
if(!empty($value)) {
if($key == "FullName") {
$key = "Full Name";
}
$resultsHTML .= "<tr><td>" . $key . ": " . $value . "</td></tr>";
}
}
$resultsHTML .= "</table></div>";
}
$data['html'] .= $row->Website . " has: <b style='color:lime;'>" . $query->num_rows() . "</b> result(s) found. This data was hacked on approximately " . $row->Date . ". <button class='btn btn-success btn-sm' style='margin-bottom:5px;' id='button" . $row->ID . "'>view results</button><div id='results" . $row->ID . "' style='display:none;'><div class='card card-outline-primary' style='margin-bottom:10px;text-align:left;margin-top:5px;'><div class='card-header card-primary'>Results</div>" . $resultsHTML . "</div></div><script type='text/javascript'>$('#button" . $row->ID . "').click(function() { $(this).hide(); $('#results" . $row->ID . "').show(); });</script><br>";
}
}
if($data['html'] == "Search completed in: " . ($end - $start) . " seconds.<p></p>") {
$data['html'] .= "No results found!<p></p>Are you searching in the right fields? Searching for an email in the phone number field will not work.<br>Make sure first and last names are correct. Example: Mike Tyson";
}
$data['html'] .= "<br><br><br>";
$this->db->from('Lookups');
$query = $this->db->get();
$new_lookup = $query->row()->Number + 1;
$qdata = array(
"Number" => $new_lookup
);
$this->db->update('Lookups', $qdata);
}
} else {
$data['html'] = '<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>Please enter something in your query before searching!</div>';
}
}
$this->load->view('welcome', $data);
}
}
所以我怎么才能在每次有人搜索时都加上这个呢?比如“查询有x个结果”
这样地:
我在许多不同的网站上搜索了这个问题,但我找不到任何关于我的具体问题。
2条答案
按热度按时间u5rb5r591#
我认为这是滥用像ci这样的框架-我给你一些关于这个框架的见解-如果你愿意学习,研究这段代码,因为你几乎不使用他的任何内置功能
在我看来,您必须重新构造代码,以至于您甚至无法识别以前的尝试;)
我试着给你一个预感-但是为了理解-你必须使用这个代码
将下列模型放入“模型”文件夹中
数据库模型
帐户模型
搜索模型
您的控制器
ps:可能是因为我刚写了一些错字
jum4pzuy2#
你已经在你的代码里用过了,
将为您提供从查询中获得的行数。