I have this code below that retrieves data from the database when the user inputs the PRD number and hits the "enter" key. It works fine for displaying single data but I need to display multiple data(PRDNO, PRDITEMCODE, PRDQTY).
Js code:
$("#prNum").keypress(function(e){
if(e.keyCode==13){
var getPR = $("#prNum").val(); //gets the value entered on supCode textbox
if($.trim(getPR) != ""){
$.post("ajax/prdetails.php", {getPR: getPR}, function(data){
if(data == "error"){
alert("Purchase Request number not found.");
$("#prNum").text("");
}
else
{
$("#displayPRD").text(data);
}
});
}
}
}); //end prNum keypress
Php code:
if(isset($_POST['getPR']) === true && empty($_POST['getPR']) === false)
{
mysql_connect('localhost', 'root', '') or die("Could not connect to server.");
mysql_select_db('cch');
$query = mysql_query("
SELECT `PRDNO` , `PRDITEMCODE` , `PRDQTY`
FROM `prdetailfile`
WHERE `PRDNO` = '" . mysql_real_escape_string(trim($_POST['getPR'])) . "'
");
if (!$query)
{
die(mysql_error());
}
echo (mysql_num_rows($query) !== 0) ? mysql_result($query, 0, 'PRDNO') : 'error';
}
I can't seem to find a way to store each column value in an array. Btw, I need to display the data by rows in an existing table in HTML and should look like this:
PRDNO | PRDITEMCODE | PRDQTY
PR001 | IC001 | 50
PR001 | IC002 | 40
PR001 | IC003 | 30
The Purchase Reuquest(PRDNO) can have multiple item orders(PRDITEMCODE) with corresponding quantity. I would greatly appreciate if someone can help me with this. THANKS!
EDIT: Sorry for the poor representation of a table. I can't post an image yet but that's how the table should look like :)