title: Defining a Javascript variable using data from a Foreach loop
body: <pre><code>&lt;? foreach ($waiting_users as $waiting_user): ?&gt;
  &lt;? echo $waiting_user-&gt;user_id; ?&gt;
  &lt;? endforeach; ?&gt;
  </code></pre>
  
  <p>I need to define the user id in a javascript variable. What is the best way of doing something like this?</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var user_id = "&lt;? echo $waiting_user-&gt;user_id; ?&gt;"; &lt;-------------???
      var post_id = "&lt;? echo $post_id; ?&gt;";
  &lt;/script&gt;
  </code></pre>
  
  <p>EDIT</p>
  
  <p>The foreach returns just one user id. It's used to display a user that has signed up for a chat. Then I use the code below which is in end.js to delete the user from a table. 
  <code>DELETE FROM table WHERE user_id = ? AND post_id = ?;</code></p>
  
  <pre><code>&lt;a class="end" href="#" title="End"&gt;End&lt;/a&gt;
  
  $(document).ready(function() {
  
      $("a.end").click(function() {
  
              $.post(base_url + "index.php/home/end", { user_id : user_id, post_id :         $(this).attr('id') }, function(data) 
              {
                      alert(data);                    
              }, "json");
  
               });
  
  
  });
  </code></pre>