Junaid Amjad Junaid Amjad - 2 years ago 63
SQL Question

My select query is not working in ajax

here is the code which i use to fetch all medicines name from database in dropdown list

$selmed = mysql_query("SELECT mnam FROM med");
echo '<select onChange="getQty();" id="pf5" name="recmed">';
while ($row = mysql_fetch_array($selmed))
{echo '<option value="'.$row['mnam'].'">'.$row['mnam'].'</option>';}

Now I want to fetch quantity against a specific medicine from database for that i use ajax as follow

var medn = $('#pf5').val();
type: "POST",
url: "getqty.php",
data: {
mednam: medn
success: function(data) {

and here is my getqty.php file where i think i am making some mistake in query

$recm = $_POST['mednam'];
$rmq = mysql_query("SELECT mqty FROM med WHERE mnam ='$recm'");
echo $rmq;

and the area where i want result on changing value shows "Resource id #5"

Answer Source

The following line does not echo result data

$rmq = mysql_query("SELECT mqty FROM med WHERE mnam ='$recm'");
echo $rmq;

Use while loop to echo all results

$rmq = mysql_query("SELECT mqty FROM med WHERE mnam ='$recm'");
while ($row = mysql_fetch_assoc($rmq)) {
    // echo fields with
    // $row['field_name'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download