我有三个潜在客户的数据表
现在我要做的是,当用户点击“Hot Leads”时,系统将从“HOT”下的潜在客户数据类别中获取5条随机记录。
以下是我的代码:
<?php
session_start();
include 'db_connect.php';
require 'logincheck.php';
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$username = mysqli_real_escape_string($conn, $_SESSION['uiduser']);
$fullname = mysqli_real_escape_string($conn, $_SESSION['fullname']);
if(isset($_GET["q"])) {
// posted data
$query_q = mysqli_real_escape_string($conn, $_GET['q']);
$status="Fresh";
$sql = "SELECT * FROM adv_leads WHERE adv_type='".$query_q."' AND
adv_status='".$status."' ORDER BY RAND() LIMIT 5";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){}else{ echo "error";}
while($build = mysqli_fetch_assoc($result))
{
echo '<tr class="select">';
echo '<td>'.$build['adv_uid_leads'].'</td>';
echo '</tr>';
}}
?>
这里
q= Type of lead i.e.HOT, COLD
Status= Fresh Leads
如果我删除WHERE
子句系统工作正常但使用WHERE
子句则返回“0”结果。
答案 0 :(得分:0)
"adv_type='".$query_q."'"
,它会检查完全匹配,而不是您可以在查询中使用
例如:
$sql = "SELECT * FROM adv_leads WHERE adv_type LIKE'%".$query_q."%' AND
adv_status='".$status."' ORDER BY RAND() LIMIT 5";