make javascript .click(function() with php
<p>I'm trying to make a series of javascript.click functions using on a loop using PHP:</p>

<pre><code>$("document").ready(function()
{    


    $('#nav &gt; li &gt; a').click(function(){
    if ($(this).attr('class') != 'active'){
      $('#nav li ul').slideUp();
      $(this).next().slideToggle();
      $('#nav li a').removeClass('active');
      $(this).addClass('active');
    }
    else{
      $(this).next().slideToggle();
    $(this).removeClass('active');
    }
    })


&lt;?php

        include_once '../admin/Clases/sql.php';
        $sql = new sql();

        $res = $sql-&gt;check("products","*","1");
        $javascript = "";
        if($res["ok"]){

            foreach($res["tabla"] as $fila)
            {
             $javascript .="$('#btn_".fila[2]."').click(function(){$('#prod_img').css('background-image','url(".fila[3].")');})";

            }
            echo $javascript;
        }

    ?&gt;
</code></pre>

<p>but when I run it doesn't work. What am I doing wrong?</p>
