I try to show Mysql result as table inside <div> after click submit button, but it just only show <table></table>. No problem found during posting value to process page.
So far, my script is like:
<form id="myform">
....................
<button id="input" type="button" class="ui-state-default ui-corner-all"><span>Submit </span></button>
<input name="action" value="openreport" type="hidden">
</form>
<div id="show"></div>
$("#submit").click(function(){
var params=$("#myform").serialize();
$.ajax({
type:"post",
url:"go.php",
data:params,
cache :false,
async :false,
success : function(result) {
$('#show').replaceWith(result);
}
});
});
page go.php:
<?php
//CONNECT TO DATABASE
$dbc=mysql_connect(_SRV, _ACCID, _PWD) or die(_ERROR15.": ".mysql_error());
mysql_select_db("qdbase") or die(_ERROR17.": ".mysql_error());
switch (postVar('action')) {
case 'openreport':
openreport(postVar('model'),postVar('line'),postVar('lot_no'));
break;
}
function openreport($model,$line,$lot_no){
$Model = mysql_real_escape_string($model);
$Line = mysql_real_escape_string($line);
$Lot = mysql_real_escape_string($lot_no);
$group=" GROUP BY DATE ";
$sql="SELECT Range_sampling,DATE(Inspection_datetime) AS DATE FROM
inspection_report WHERE Model LIKE '".$Model."'";
$sql.="AND Line LIKE '".$Line."' AND Lot_no LIKE '".$Lot."'".$group;
$result=mysql_query($sql) or die(_ERROR26.": ".mysql_error());
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo("<tr><td>$row[0]</td><td>$row[1]</td></tr>");
// echo "<tr>";
// echo "<td>" . $row['Range_sampling'] . "</td>";
// echo "<td>" . $row['DATE'] . "</td>";
// echo "</tr>";
}
echo "</table>";
mysql_close($dbc);
}
?>
I have no idea because I’m not really understand how to show mysql result as a html table.

The AJAX call is made only if a button is clicked that has an id of “submit”; however, your submit button has an id of “input”. Try changing the line that reads:
$("#submit").click(function(){to
$("#input").click(function(){As Yun suggested, to keep
<div id="show">...</div>wrapped around the table, change$('#show').replaceWith(result);with
$('#show').html(result);I don’t know if this will help or not, but it’s the only thing that stands out to me.