Welcome Guest, Not a member yet? Register   Sign In
Weird string length on vardump in php, datatable, codeigniter
#1

[eluser]jigarjain[/eluser]
I am facing a really strange problem which i am debugging from past 2 hours but unable to find the solution. Before explaining the problem, let me show the code

My Controller Function is

Code:
$this->load->library('datatables');
    $actionLinkBar = $this->load->view("content/updates/dt_files/action_bar", array(), TRUE);
    $this->datatables
            ->select("id, name, status")
            ->where('id', $this->session_data['user_id'])
            ->from("t_user")
            ->add_column("action", $actionLinkBar, 'id, name, status');

    echo $this->datatables->generate();

And the code in my action_bar view is

Code:
<?php
     $status_rec = '$3';
     var_dump($status_rec); // STRANGE OUTPUT -  string(2) "1"
     ?>

<div class="action_bar" data-update-id="&lt;?php echo '$1'; ?&gt;">

    &lt;?php if ($status_rec == '1') { ?&gt; // HENCE COMPARISON ALWAYS FAILS

         <span>Present</span>

    &lt;?php }else { ?&gt;

         <span>Absent</span>

     &lt;?php } ?&gt;

</div>

Now explaining the problem.. I am using Datatables with Codeigniter. I have a view template action_bar which will be displayed in one of the columns of datable in front end. The view has if/else condition based on value of status field from DB. If status feild = value 1 = Present Else Absent. But though the $status_rec has value as '1' it still fails in comparison. Strange thing is var_dumping, i found that though it has proper value, the length is weird & maybe thats why the comparison is failing. Your help is really needed :/

P.S - The DB feild that holds this value is int with length 1
#2

[eluser]Tpojka[/eluser]
Try with int.
Code:
&lt;?php if ($status_rec == 1) { ?&gt;
#3

[eluser]jigarjain[/eluser]
Tried but doesnt work..
#4

[eluser]CroNiX[/eluser]
$status_rec = '$3';

You're setting $status_rec to a literal string since you are using single quotes.

&lt;?php echo '$1'; ?&gt;
same here. You are echoing a literal $1. Are these supposed to be a variable? $3, $1?
#5

[eluser]jigarjain[/eluser]
They are supposed to be accessed the same way. Check the link

add_column("action", $actionLinkBar, 'id, name, status');

On echoing, I get proper value

#6

[eluser]Tpojka[/eluser]
Good point CroNiX.
Variable name should NOT be started with number.




Theme © iAndrew 2016 - Forum software by © MyBB