0

As the title says I'm having difficulties connecting php variable into javascript for loop. Here's the code:

$(document).ready(function()
{
    for (i = 3; i <= <?php echo (int)$description_count?>; i++)
    { 
        $("#row"+i).css('display','inline-block');
    }
});

It doesn't loop at all, when I try looping with normal number instead of echoing variable everything works fine, what's the problem?

Donny
  • 47
  • 1
  • 8

1 Answers1

3

I guess there is some syntax error. Check it in view source whether the value comes. Try -

$(document).ready(function()
{
   for (i = 3; i <= <?php echo $description_count; ?>; i++)
   { 
       $("#row"+i).css('display','inline-block');
   }
});
Parag Tyagi
  • 8,780
  • 3
  • 42
  • 47
  • Tried this way, didn't helped. – Donny Jul 28 '14 at 07:51
  • Check it in `view source` – Parag Tyagi Jul 28 '14 at 07:52
  • have you tried this: echo json_encode($description_count); – dgierejkiewicz Jul 28 '14 at 07:53
  • @dariusz.g I just got a 'null' out of that,so I'm guessing the mistake is because I'm sending null variable. – Donny Jul 28 '14 at 07:55
  • before you fire your js code, just try to var_dump your variable and then look what you are getting exactly in your var – dgierejkiewicz Jul 28 '14 at 08:00
  • I'll accept this answer, though dariusz.g got me to the answer, whoever going to need this in future should look at comments. The thing was that instead of writing $lesson_count I wrote $description_count which was the variable of input that I posted, I put that input into $lesson_count variable so that was my foolish mistake, though thanks a lot for helping guys :) – Donny Jul 28 '14 at 08:03