2

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.

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

My php fetch is as follows:

$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:

$(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.

4
  • Why do you have allDay twice in the array? Also you're mixin single and double quotes all over the place, not a good habit.. Commented Apr 18, 2012 at 20:45
  • That's funny, I was trying to fix it and never actually went back and erased the last one. Commented Apr 18, 2012 at 20:47
  • What column type are you using to store the true/false values? Commented Apr 18, 2012 at 20:47
  • @liquorvicar tinyint. i read that stores values at boolean values not strings. Commented Apr 18, 2012 at 20:48

3 Answers 3

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.

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.

Sign up to request clarification or add additional context in comments.

5 Comments

If i do that, then I need to edit my javascript to say if its string leave as is and if its a true/false return the value?
If done correctly, you should be able to just evaluate it as true or false. Try doing a var_dump on return before json_encode in your PHP to list all of the types and values of the array, so we know for sure what type allDay is.
var_dump says ["allDay"]=> string(1) "1"
That's different... well, try "allDay" => intval($row['allDay']) or "allDay" => $row['allDay'] == "1". The former will convert string(1) "1" to int(1) which will evaluate true.
Very nice work. It worked. I'll test a bit more and check it out.
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;

1 Comment

it actually gave me the right values, but is still showing it as a string.
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'";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.