Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing query on the same page AJAX
    primarykey
    data
    text
    <p>i'm still fresh in using AJAX and i'm having hard time with it.can you please help me with this? i actually have a dropdown and when i select an item in that dropdown a table of queries should print to the tbody.here's my code:</p> <p><strong>the PHP code:</strong></p> <pre><code>&lt;select id="proj_id" name="proj_id" onchange="myFunction(this.value)"&gt; &lt;option value="none"&gt;---select project---&lt;/option&gt; &lt;?php //Projects $r = @mysql_query("SELECT `proj_id`, `proj_name` FROM `projects`"); while($rows = mysql_fetch_assoc($r)) { $proj_id = $rows['proj_id']; $proj_name = $rows['proj_name']; echo '&lt;option value='.$proj_id.'&gt;'.$proj_name.'&lt;/option&gt;'; } ?&gt; &lt;/select&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Project Name&lt;/th&gt; &lt;th&gt;Material Name&lt;/th&gt; &lt;th&gt;Quantity&lt;/th&gt; &lt;th&gt;Status&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody id="project_estmat"&gt; &lt;?php //Display Requests $r = @mysql_query("SELECT `proj_name`, `mat_name`, `req_qty`, `stat_desc` FROM `requests` JOIN `projects` USING(`proj_id`) JOIN `materials` USING(`mat_id`) JOIN `status` ON(requests.stat_id = status.stat_id)"); while ($row = mysql_fetch_array($r)) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'.$row['proj_name'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['mat_name'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['req_qty'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['stat_desc'].'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } ?&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p><strong>jS CODE:</strong></p> <pre><code>function myFunction(value){ if(value!="none") { $.ajax( { type: "POST", url: 'content/admin/requests.php', data: { proj_id: value}, success: function(data) { $('#project_estmat').html(data); } }); } else { $('#project_estmat').html("select an item"); } } </code></pre> <p>and I have this PHP code that should be in the #project_estmat which is a table. And I think this is where the problem lies. Because everytime I select an item, nothing is printing in the table. It shows empty data.</p> <pre><code>&lt;?php if (isset($_POST['proj_id'])) { $r = @mysql_query("SELECT `proj_name`, `mat_name`, `req_qty`, `stat_desc` FROM `requests` JOIN `projects` USING(`proj_id`) JOIN `materials` USING(`mat_id`) JOIN `status` ON(requests.stat_id = status.stat_id)"); if($r){ while ($row = mysql_fetch_array($r)) { echo '&lt;tr&gt;'; echo '&lt;td&gt;'.$row['proj_name'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['mat_name'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['req_qty'].'&lt;/td&gt;'; echo '&lt;td&gt;'.$row['stat_desc'].'&lt;/td&gt;'; echo '&lt;/tr&gt;'; } } exit; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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