日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php fetch返回false,Php fetch返回字符串而不是布爾值“true / false”值

發布時間:2025/3/12 php 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php fetch返回false,Php fetch返回字符串而不是布爾值“true / false”值 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

I'm using full calender and I have a few events that are all day events. Generally, my php set all 'allDay' => 'false'. Now that I noticed it adds a time on it if I do not specify a time.

我正在使用完整的日歷,我有一些事件是全天活動。一般來說,我的php設置所有'allDay'=>'false'。現在,我注意到如果我沒有指定時間,它會增加時間。

I want to set all defaults false for all values, unless I specify them true.

我想為所有值設置所有默認值false,除非我將它們指定為true。

My php fetch is as follows:

我的PHP提取如下:

$sql = "SELECT `id`, `title`, `time`, `start`, `end`, `url`, `backgroundColor`, `textColor`, `className`,

`allDay` FROM calender WHERE length('column') > '0'";

$result = $dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);

foreach ($result as $row){

$return[]=array('id'=>$row['id'],

'title'=>$row['title'],

"allDay" =>$row['allDay'],

'start'=>$row['start'].' '.$row['time'],

'end'=>$row['end'],

'url'=>$row['url'],

'backgroundColor'=>$row['backgroundColor'],

'textColor'=>$row['textColor'],

'className' =>$row['className']);

}

$dbh = null;

header('Content-type: application/json');

echo json_encode($return);

and the jQuery function is:

和jQuery函數是:

$(document).ready(function() {

$('#calendar').fullCalendar({

editable: false,

events: "json-events.php",

eventDrop: function(event, delta) {

alert(event.title + ' was moved ' + delta + ' days\n' +

'(You cannot update these fields!)');

},

loading: function(bool) {

if (bool) $('#loading').show();

else $('#loading').hide();

},

});

});

I do not know where I add the values. I have mySQL storing 'allDay' as true/false but it returns as a string. So I actually know how to go about coverting it before json encodes the file. or have jQuery/javascript change it after the data is being looked at.

我不知道我在哪里添加值。我有mySQL存儲'allDay'為true / false但它返回為字符串。所以我真的知道如何在json編碼文件之前轉換它。或者在查看數據后讓jQuery / javascript更改它。

3 個解決方案

#1

2

What type is the allDay field in MySQL? If it's an enum('true', 'false'), that's probably your problem. That gets converted to a string. I've had people do this, and it took me forever to figure out why what I thought was a boolean (or an int) was a string.

MySQL中的allDay字段是什么類型的?如果它是枚舉('true','false'),那可能是你的問題。這會轉換為字符串。我有人這樣做,我花了很長時間才弄清楚為什么我認為布爾(或int)是一個字符串。

Double check your database and try making it a tinyint(1) and using 0 for false and 1 for true. PHP's boolean true and false will get casted to the corresponding integers and you won't have a problem using 0/1 in JavaScript.

仔細檢查您的數據庫並嘗試將其設為tinyint(1)並使用0表示false,使用1表示true。 PHP的布爾值true和false將被轉換為相應的整數,在JavaScript中使用0/1時不會有問題。

#2

0

Try this:

foreach ($result as $row){

$return[]=array('id'=>$row['id'],

'title'=>$row['title'],

"allDay" =>$row['allDay'] == "true",

'start'=>$row['start'].' '.$row['time'],

'end'=>$row['end'],

'url'=>$row['url'],

'backgroundColor'=>$row['backgroundColor'],

'textColor'=>$row['textColor'],

'className' =>$row['className']);

}

$dbh = null;

#3

0

You could allso try this:

你也可以試試這個:

$sql = "SELECT `id`, `title`, `time`, `start`, `end`, `url`, `backgroundColor`, `textColor`, `className`, IF(`allDay` = 'true',true,false) AS allDay FROM calender WHERE length('column') > '0'";

總結

以上是生活随笔為你收集整理的php fetch返回false,Php fetch返回字符串而不是布爾值“true / false”值的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。