Mysql-根据用户输入参数从多个表中获取过滤结果

时间:2018-12-15 09:23:38

标签: mysql

我有一个ajax查询来显示来自多个表的过滤结果为

abc.com/results.php?page=1&categories=&sizes=&prices=&imp=&type=&search=&sort=0

https://adclerks.com网站上进行搜索市场。这是非常复杂的查询。我的当前代码在下面给出,但我无法完全进行此复杂的查询。有人可以给我个主意,如何实现这个查询      

include( $_SERVER['DOCUMENT_ROOT'] . '/conn.php' );


$page=$_GET['page'];
$categories=$_GET['categories'];
$sizes=$_GET['sizes'];
$prices=$_GET['prices'];
$imp=$_GET['imp'];
$type=$_GET['type'];
$search=$_GET['search'];
$sort=$_GET['sort'];




$host = "localhost";
$username = "";
$password = "";
$db = "";
$onee="1";

$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
$link = new PDO("mysql:host=$host;dbname=$db", $username, $password, $options);
$stmt = $link->prepare("SELECT * from websitez WHERE pubverify= ?");
$stmt->execute([$onee]);
$result = $stmt->fetchAll();

$row_count = $stmt->rowCount();  

if ("1" == "1")
{


foreach ($result as $row):

$srid=$row['srid'];
$webtitle=$row['webtitle'];
$webcategory=$row['webcategory'];
$usermonimpress9=$row['usermonimpress9'];
$weburl=$row['weburl'];
$featured=$row['featured'];


// Associative array
$cities = array("1"=>"Affiliate, SEO & Marketing", "2"=>"All Things Apple", "3"=>"Automotive", "4"=>"Beauty & Fashion", "5"=>"Business & Finance", "6"=>"Cryptocurrency", "7"=>"Education", "8"=>"Entertainment", "9"=>"Family & Religion","10"=>"Gaming & Humor", "11"=>"Government & Politics","12"=>"Health & Fitness", "13"=>"Home & Architecture", "14"=>"Online Community", "15"=>"Pets", "16"=>"Sports", "17"=>"Technology", "18"=>"Travel", "19"=>"Visual Arts & Design","20"=>"Web Design & Development");


$now=time();
$month = 2592000;
$oldfrom= $now - $month;
$day1='86400';
$oldlastday= $now - $day1;
$null="";

$stmt_check = $conn->prepare("SELECT * FROM webstats WHERE websrid =? AND pubadhash =? AND time BETWEEN $oldlastday AND $now");
$stmt_check->bind_param("ss", $srid, $null);
$stmt_check->execute();
$stmt_check->store_result();
$monthlywebtotalvisitorsss = $stmt_check->num_rows;
$stmt_check->close();
$monthlywebtotalvisitors=30 * $monthlywebtotalvisitorsss;
$monthlyimpression = number_format("$monthlywebtotalvisitors");


$number1=$monthlywebtotalvisitors;

if ($number1 < 1000000) {
    // Anything less than a million
    $format1 = number_format($number1 / 1000, 1) . 'K';

} else if ($number1 < 1000000000) {
    // Anything less than a billion
    $format1 = number_format($number1 / 1000000, 1) . 'M';
} else {
    // At least a billion
    $format1 = number_format($number1 / 1000000000, 1) . 'B';
}



// GET ANY ZONE DATA FROM ZONES TABLE
$stmt = $conn->prepare("SELECT zoneprice, zonetype FROM zonez WHERE misc1= ? LIMIT 1");
$stmt->bind_param("s", $weburl);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($zonepricee, $zonetype);
$stmt->fetch();

$zoneprice=$zonepricee;

?>

<div class="col-md-4 col-xs-12">
    <a href='//abc.com/detail.php?site=<?php echo $srid; ?>' class='a-site'>
    <img src="//abc.com/assets/screenshots/<?php echo $srid; ?>.png" width="100%" class="img-responsive" style="border:1px solid rgba(29,29,33,0.07);" onerror="this.onerror=null;this.src='//abc.com/assets/images/no_screenshot.jpg';">

                        <div class='site-details'>
        <h3><?php echo $webtitle; ?> <?php if($featured=="yes")
 {

echo "<i class='fa fa-star featured_star'></i>";


 }
?></h3>
        <p class='category'><?php echo $cities["$webcategory"]; ?></p>
        <div class='site-meta'><div><span><i class='fa fa-bar-chart'></i> <?php echo $format1; ?></span> Impressions</div><div><span class=''><i class='fa fa-shopping-cart'></i> $<?php echo $zoneprice; ?></span> <?php if($zonetype=="1")
 {

echo "Per month";


 }
 else if($zonetype=="2")
 {

echo "Per 1K imps";

 }

?></div></div>
        </div>

</a>

                            </div>



<?php

endforeach;

}

else
{

}

?> 

0 个答案:

没有答案