Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating JSON object from DB results to post back into jquery UI Dialog, using ajax post method
    text
    copied!<p>I have a script that loads sample images from DB on page load from relevant category in the DB. </p> <pre><code>&lt;?php $category = 'granite'; $samples = 'SELECT * FROM material WHERE material_type = :cat'; $res = $db-&gt;prepare($samples); $res-&gt;execute(array(':cat' =&gt; $category)); $count = $res-&gt;rowCount(); if($count &gt; 0) while ($row = $res -&gt; fetch()){ $postimggranite = $row[mat_image]; $postidgranite = $row[id]; ?&gt; &lt;?php echo "&lt;div class='sample'&gt;"; echo "&lt;h3 class='sample_h'&gt;$row[name]&lt;/h3&gt;"; echo "&lt;a href='/images/granite-worktops/samples/$postimggranite'&gt;&lt;img src='/images/granite-worktops/thumbs/$postimggranite' alt='$row[name]' width='100' height='100' class='aligncenter size-full' title='$row[name]'&gt;&lt;/a&gt;"; echo "&lt;br /&gt;&lt;a class=\"button\" href=\" \" rel=\"nofollow\" onClick=\"user_notice(this,''); return false;\"&gt;More Details&lt;/a&gt;"; echo "&lt;/div&gt;"; } ?&gt; </code></pre> <p>As you can see from the script above in the last echo before closing a div I have a "More Details button, by clicking on which the dialog appears on the screen where I need to display additional information from the same DB. Method I am planning to use is </p> <pre><code>function user_dialog(a,b){ "undefined"!=typeof jQuery.ui?($("#dialog").attr("title","Detailed Information").html(a), $("#dialog").dialog({ modal:true, width:400, buttons: { Cancel: function() { $(this).dialog("close"); }, Download: function(){ $(this).dialog("close"); window.location=b } } } )) :window.location=b} function user_notice(a){ download_link=$(a).attr("href"); $.ajax({ type:"POST", url:"/includes/json.php", data:"action=reminder&amp;thepath="+download_link, dataType:"json", error:function(){ window.location=download_link }, success:function(a){ 1==a.status&amp;&amp;user_dialog(a.html,download_link); } }) }; </code></pre> <p>Here also the script of my json.php file </p> <pre><code>&lt;?php header('X-Robots-Tag: noindex, noarchive'); $a = session_id(); if(empty($a)) session_start(); if($_SERVER['HTTP_REFERER']){ $resp_dialog = array( 'status' =&gt; 1, 'html' =&gt; '&lt;p&gt;Here is you sample and rest of staff&lt;/p&gt;' ); echo json_encode($resp_dialog); }else{ header('HTTP/1.1 403 Forbidden'); exit; } ?&gt; </code></pre> <p>clearly it all works and the line <code>&lt;p&gt;Here is you sample and rest of staff&lt;/p&gt;</code> is appearing in the dialog, but what I actually need is to create a json object that brings additional info from DB and have no idea where, inside the <code>json.php</code> file or create some sort of additional file and place in href with <code>urlid="something to get fromdb"</code> than <code>$_GET['urlid']</code> in the <code>json.php</code> to send it do DB. Basically have no idea of what and where to do it.</p> <p>Please go easy on me since I am still learning this all and most of it is still pretty new for me, so forgive me if I have not explained something correctly.</p>
 

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