Welcome Guest, Not a member yet? Register   Sign In
How do i check if table item is either true or false

(This post was last modified: 02-11-2016, 03:00 AM by kaaai3.)

I am making an list where people can make a blog post active or inactive so i have to check if the status is active or not.
I have a table item called active in my database this is a boolean.

How would i achieve this  I have a begin of the view wether it displays an active post or inactive(this part works) but no clue how this would work in the controller or model.
I use font-awesome to display if the post is active or not

PHP Code:
<a href="<?php echo site_url('posts/activate/'. $post_item['id']); ?>">
if($post_item['active'] == 1) {
 echo '<i class="fa fa-check-square-o fa-lg"></i>';
 } else {
'<i class="fa fa-square-o fa-lg"></i>';


I am not certain what the correct thing is here, but I always store a 1 or a 0 in a tinyint(1) field for true or false. Then I check the value to see if it is a 1 or not. So the way you are going about it seems right to me.

How you deal with that is up to you, depending on what you want to achieve. You could have a checkbox that is checked or not depending on the 'active' result, or you could output two different buttons, one for 'make active' and one for 'make inactive'. Or you could hide everything about your post form with a 'This post is currently disabled message'.

To manage the 'make active' button in your controller, just send a value to the controller that is otherwise set to FALSE,

Something like...
PHP Code:
class Blog_post extends CI_Controller {

 public function view($make_active=FALSE)

     if ($make_active == 1)
         ... do whatever


Or if you are doing it in a form, check the value of the post field and if it is set to the right value toggle the database value for that field.

There are so many ways to do what you are asking, I cannot really add any more.

Hope that helps in some way,


Theme © iAndrew 2016 - Forum software by © MyBB