Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript to PHP for Popup Window Content
    text
    copied!<p>I have a map with numerous markers on it. </p> <p><strong>I need help connecting my Javascript with my PHP file so I can pull the relevant content from the database and put it inside the div of a popup window.</strong> The map and the popups work well, they open, but I just don't know how to insert content from the database into the div #popupcontent.</p> <p>Here is part of the JavaScript:</p> <pre><code> function showPopup(id, leftbul, topbul){ map.find(settings.popupSelector).fadeOut(); var boxid = '#' + id + '-box'; $(boxid).fadeIn(); $(settings.popupCloseSelector).click(function(){ $(this).parent().fadeOut() }); } </code></pre> <p>The JavaScript/Ajax references a seperate HTML file where the popup markers are recorded. Each marker / popup has the following HTML, one after each other in the same file. In this instance the id references the land parcel identified as 97. </p> <pre><code>&lt;a href="javascript:void(0)" id="97" class="bullet" style="color: rgb(0,0,0);font-size: 13px;" rel="222-156"&gt;97&lt;/a&gt; &lt;div class="popup" id="97-box" style="top:158px;left:220px;"&gt; &lt;h3&gt;97&lt;/h3&gt; &lt;div class="popupcontent"&gt; &lt;p&gt;Insert my database content here &lt;/p&gt; &lt;/div&gt; &lt;a class="close" href="javascript:void(0)"&gt;Close&lt;/a&gt; &lt;/div&gt; </code></pre> <p>I believe I need to insert something like this in the JavaScript, but I'm not getting it to work. Do you think you can help me here?</p> <pre><code>$.get("popup.php", (id), function( data ) { var content = $( data ).find( '#content' ); $( "#popupcontent" ).empty().append( content ); } </code></pre> <p>This is the server side PHP file:</p> <pre><code>&lt;?php $id=$_GET["id"]; // Connects to your Database mysql_connect("mysql.url.com", "username", "password") or die(mysql_error()); mysql_select_db("database_name") or die(mysql_error()); $data = mysql_query("SELECT * FROM inventory WHERE lot_number = '".$id."'";) or die(mysql_error()); Print "&lt;table border cellpadding=3 font-size:8px width:200px&gt;"; while($info = mysql_fetch_array( $data )) { Print "&lt;tr&gt;"; Print "&lt;th&gt;Lot number:&lt;/th&gt; &lt;td&gt;".$info['lot_number'] . "&lt;/td&gt;&lt;/tr&gt; "; Print "&lt;th&gt;Sales Status:&lt;/th&gt; &lt;td&gt;".$info['lot_status'] . "&lt;/td&gt; "; Print "&lt;th&gt;Model Built:&lt;/th&gt; &lt;td&gt;".$info['model'] . "&lt;/td&gt;&lt;/tr&gt; "; Print "&lt;th&gt;Lot Size:&lt;/th&gt; &lt;td&gt;".$info['lot_size'] . " &lt;/td&gt;&lt;/tr&gt;"; Print "&lt;th&gt;Frontage:&lt;/th&gt; &lt;td&gt;".$info['lot_frontage'] . " &lt;/td&gt;&lt;/tr&gt;"; Print "&lt;th&gt;Depth:&lt;/th&gt; &lt;td&gt;".$info['lot_depth'] . " &lt;/td&gt;&lt;/tr&gt;"; Print "&lt;th&gt;Premium:&lt;/th&gt; &lt;td&gt;".$info['lot_premium'] . " &lt;/td&gt;&lt;/tr&gt;"; Print "&lt;th&gt;Features:&lt;/th&gt; &lt;td&gt;".$info['lot_features'] . " &lt;/td&gt;&lt;/tr&gt;"; Print "&lt;th&gt;Restrictions:&lt;/th&gt; &lt;td&gt;".$info['lot_restrictions'] . " &lt;/td&gt;&lt;/tr&gt;"; Print "&lt;th&gt;Move-in Date:&lt;/th&gt; &lt;td&gt;".$info['lot_move_date'] . " &lt;/td&gt;&lt;/tr&gt;"; } Print "&lt;/table&gt;"; ?&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