Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I refer to a php variable in jQuery?
    text
    copied!<p>I'm a complete beginner with jQuery and I have this bit of script here and I want to mix jQuery with PHP. I have Courses and in those Courses are Lessons. A Teacher is assigned to teach a Course. What I want is a link where if I press it a popup appears and in it shows the Lesson details or Course details. My problem is that I will be having multiple links and thus dialogs/modal windows in a page such that $l['id'] and $c['id'] will be different. How can I therefore use $l['id'] and $c['id'] in or with jQuery given that the jQuery script is inside the view file and I'm creating the actual content itself in the controller and passing it onto view. Sorry if I don't make sense cause I'm still quite confused about all this myself. </p> <pre><code>view.php &lt;script type="text/javascript"&gt; $(function(){ // setup ul.tabs to work as tabs for each div directly under div.panes $("#tabs").tabs(); $('#dialog').dialog({ modal: true }); }) &lt;/script&gt; &lt;h1&gt;Student Hub: Courses for &lt;?php echo $studentName;?&gt;&lt;/h1&gt; &lt;div id="tabs"&gt; &lt;?php echo $content;?&gt; &lt;/div&gt; controller.php This is in a foreach loop &lt;div class="lessonDetails"&gt; &lt;p&gt;&lt;a href="#lessonInfo'.$l['id'].'"&gt;Lesson Details:&lt;/a&gt;&lt;p&gt; &lt;div id="lessonDialog'.$l['id'].'" title="Lesson Details"&gt; '.$l['name'].' &lt;/div&gt; &lt;/div&gt; &lt;div class="courseDetails"&gt; &lt;p&gt;&lt;a href="#courseInfo'.$c['id'].'"&gt;Course Timetable &amp; Resources&lt;/a&gt;&lt;p&gt; &lt;div id="courseDialog'.$c['id'].'" title="Course Details"&gt; &lt;p&gt;'.$c['fullname'].'&lt;/p&gt; &lt;p&gt;'.$c['summary'].'&lt;/p&gt; &lt;p&gt;Upcoming Lessons: &lt;/p&gt; &lt;/div&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload