Php mysql中的整数始终返回0
我有一些从mysql数据库中提取数据的代码,一切都很好,日期、变量等等。我遇到的问题是唯一的整数每次都返回0Php mysql中的整数始终返回0,php,mysql,Php,Mysql,我有一些从mysql数据库中提取数据的代码,一切都很好,日期、变量等等。我遇到的问题是唯一的整数每次都返回0 while($row = mysqli_fetch_array($result)) { $fufilled = "1"; $flag = $row['flag']; $shopnumb = $row['Shopnumb']; $shoptype = $row['Shop_type']; ... $shoptype和$shoptnumb都返回正确的内容,但是$flag每次都返回0,即使数
while($row = mysqli_fetch_array($result)) {
$fufilled = "1";
$flag = $row['flag'];
$shopnumb = $row['Shopnumb'];
$shoptype = $row['Shop_type'];
...
$shoptype
和$shoptnumb
都返回正确的内容,但是$flag每次都返回0,即使数据库的5行有1,1,1,0
CREATE TABLE `Shop_data` (
`Shopnumb` int(15) NOT NULL AUTO_INCREMENT COMMENT 'shop id number',
`flag` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1=unread 0=read',
`CID` int(15) NOT NULL COMMENT 'Client this shop belongs to',
`SID` varchar(50) DEFAULT NULL COMMENT 'identifys which survey to use',
`comp_date` date DEFAULT NULL COMMENT 'Completion Date',
`sched_date` date DEFAULT NULL COMMENT 'Scheduled shop date',
`shop_comp` smallint(1) NOT NULL DEFAULT '0' COMMENT 'shopper submitted report',
`edit_comp` smallint(1) NOT NULL DEFAULT '0' COMMENT 'Report has been edited',
`return_shop` smallint(1) NOT NULL DEFAULT '0' COMMENT 'return report to shopper for editing',
`report_comp` smallint(1) NOT NULL DEFAULT '0' COMMENT 'report ready for client',
`Shop_type` varchar(50) DEFAULT NULL,
`Shoploc` varchar(100) DEFAULT NULL,
`shop_cost` decimal(10,2) DEFAULT NULL COMMENT 'Normal or adjusted cost of shop',
`shop_reimb` decimal(10,2) DEFAULT NULL COMMENT 'Shopper reimburstment cost',
`shop_pay` decimal(10,2) DEFAULT NULL COMMENT 'Total cost',
`shopper_assign` varchar(200) DEFAULT NULL COMMENT 'Identifys which shopper assigned',
PRIMARY KEY (`Shopnumb`),
UNIQUE KEY `Shopnumb` (`Shopnumb`)
) ENGINE=MyISAM AUTO_INCREMENT=2252 DEFAULT CHARSET=latin1
我的问题
SELECT * FROM Shop_data WHERE CID='".$_SESSION['CID']."' AND report_comp='1' AND DATEDIFF(CURDATE(), comp_date) <".$lengthoftime." ORDER BY comp_date DESC;
SELECT*FROM Shop_data,其中CID=”、“$_SESSION['CID']”,并报告_comp='1'和DATEDIFF(CURDATE(),comp_date)语句
if ($flag = '0') {
是赋值,并且将始终为真(其计算结果为赋值,即字符串)。你需要:
if( ! intval($flag)) {
您需要提供更多信息-SHOW CREATE TABLE yourtable
,您正在运行的查询以及在mysql客户端中运行该查询的结果将是一个良好的开端……还要确认它返回“0”而不是“NULL”,并确认索引位于数组中(isset($row['flag'))。当转换为整数时,它们都将显示“0”,但它们是不同的,并给出不同的错误提示。下一次调试,“print_r($row);”,因为这将显示实际的行数据。如果是0,那么在数据库中是0。如果它在数组中是“1”,那么您将在其他地方将其更改为“0”。好的,我认为我的If语句-print\R($flag)存在问题if语句前面和后面都返回了正确的值,但是if语句执行的所有操作都是0,因为上面的问题解决了,if语句没有得到==我感谢所有的帮助
if( ! intval($flag)) {