Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing values from MySql/PHP script to jquery
    text
    copied!<p>I'm new in jQuery and I'm trying to do this:</p> <p>In my php file, I read <code>tours</code> table, and make a link button to open a modal windows, where user will select date, number of adults and number of child. But I need to pass the value of variable <code>$tourID</code>, so in the modal window I can diaplay the tour details and picture.</p> <p><strong>cart.php</strong></p> <pre><code> &lt;div style="float:left;border:1px solid blue;width:400px;margin-left:20px;"&gt; &lt;div style="border:1px solid #EEE;font-size:12px"&gt; &lt;?php $query_tours = "Select * from tours where feautured = 'Y' " ; $result_tours = mysql_query($query_tours); while($row=mysql_fetch_array($result_tours )) { $tourID = $row['recid']; echo '&lt;div style="border:1px solid #EEE;font-size:12px"&gt;'; print "$tit_esp - $tourID &lt;br&gt;"; print "Adults : $adrate | Child : $chrate "; print "&lt;a href='#?tourid=$tourID' class='myTour_$tourID'&gt;see details&lt;/a&gt;"; print "&lt;/div&gt;"; } ?&gt; &lt;/div&gt; </code></pre> <p>In my jQuery script, I open the modal window, and the input section, but I cannot receive the value of <code>$tourID</code>. I already tried this:</p> <pre><code>var tour = "&lt;?php echo $tourID; ?&gt;"; </code></pre> <p>but I'm receiving an error message: </p> <blockquote> <p>Uncaught SyntaxError: Unexpected token &lt; b>Notice: Undefined variable: tourID in <strong>C:\wamp\www\travel_depot\head_esp.php</strong> on line <strong>429</strong></p> </blockquote> <p>Here is my jquery sript :</p> <pre><code>&lt;script type="text/javascript"&gt; $(function() { $( "#dialog-form" ).dialog({ position: 'center', autoOpen: false, draggable: true, height: 300, width: 410, modal: true, show : { transitionIn: 'blind', transitionOut: 'explode', }, open: function(event, ui) { $( "#datepicker" ).datepicker('enable'); var tour = "&lt;?php echo $tourID; ?&gt;"; alert(tour) $.ajax({ url: 'tour_cont.php', data: "regis=" + regis + "", dataType: 'json', success: function(data){ var titulo = data[1]; var shotdes = data[3]; $( "#dialog-form" ).append( "&lt;tr&gt;" + "&lt;td width='21%'&gt;" + titulo + "&lt;/td&gt;" + "&lt;/tr&gt;" ); } }); }, }); $('a[class^=myTour]') .button() .click(function() { $( "#dialog-form" ).dialog( "open" ); }); }); &lt;/script&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