为什么此查询不显示多个数据。即使我有10/12数据,但这条线只显示1.检查我将它限制为3但它只显示1.
$getAds = mysql_query("SELECT *
FROM advertises
WHERE status='RUNNING'
AND adult='0'
AND (country LIKE '%$test%' OR country='ALL')
AND (device LIKE '%$pabu%' OR device='ALL')
ORDER BY rand()
LIMIT 0,3");
我的数据库结构
表advertises
的表结构 -
CREATE TABLE `advertises` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userid` int(11) NOT NULL, `name` varchar(5000) NOT NULL, `url` varchar(5000) NOT NULL, `type` varchar(500) NOT NULL, `device` varchar(500) NOT NULL, `country` varchar(500) NOT NULL, `time` varchar(500) NOT NULL, `status` varchar(500) NOT NULL, `dset` varchar(500) NOT NULL, `cset` varchar(500) NOT NULL, `acpc` varchar(500) NOT NULL, `ucpc` varchar(500) NOT NULL, `adult` tinyint(10) unsigned NOT NULL DEFAULT '0', `title` varchar(500) NOT NULL, `pcpc` varchar(500) NOT NULL DEFAULT '0', `spent` varchar(500) NOT NULL DEFAULT '0', `adc` varchar(500) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1;
------ - - 转储表advertises
-
INSERT INTO `advertises` VALUES ('1','1','dqui.com/adultb.php','lt.adqui.com','banner','ALL','ALL','Saturday , September 19 , 2015','RUNNING','no','no','0.015','0.012','1','Android Adult','0.005','49999.925',''); INSERT INTO `advertises` VALUES ('2','1','http://adqui.com/banner.php','http://kid.adqui.com','banner','ALL','ALL','Saturday , September 19 , 2015','RUNNING','no','no','0.01','0.008','0','Android Non','0.002','49999.88','');
INSERT INTO `advertises` VALUES ('3','1','qui.com/adultb.php','lt.adqui.com','banner','ALL','ALL','Saturday , September 19 , 2015','RUNNING','no','no','0.0002','0.0002','1','Adult','0.00','4999.874','0.0002'); INSERT INTO `advertises` VALUES ('4','1','adqu i.com/banner.php','kid.adq ui.com','banner','ALL','ALL','Saturday , September 19 , 2015','RUNNING','no','no','0.0002','0.002','0','non','','4999.923','0.0008');
答案 0 :(得分:0)
Status是mysql中的关键字。所以试试这个
$getAds=mysql_query("SELECT * FROM advertises WHERE `status`='RUNNING' AND adult='0' AND (country LIKE '%test%' OR country='ALL') AND (device LIKE '%pabu%' OR device='ALL') ORDER BY rand() LIMIT 0,3");
答案 1 :(得分:0)
您是否尝试过对mysql_query返回的结果使用mysql_fetch_assoc? 请参阅mysql-query manual,特别是示例#2
答案 2 :(得分:0)
mysql_query()
已被弃用,您可以改用PDO。
尝试以下,
<?php
$dbcon = new PDO("mysql:host=localhost;dbname=test", 'root', '');
$test = 'All';
$pabu = 'All';
$qry = "SELECT *
FROM advertises
WHERE status='RUNNING'
AND adult='0'
AND (country LIKE '%$test%' OR country='ALL')
AND (device LIKE '%$pabu%' OR device='ALL')
ORDER BY rand()
LIMIT 0,3";
$rq = $dbcon->query($qry);
$op = ( $rq ) ? $rq->fetchAll(PDO::FETCH_ASSOC) : '';
echo '<pre>'; print_r($op);
?>