I have a table sets in a popup window to show orders placed by a specific userID
<div id="shpcart">
<div id="shpop">
<table>
<thead>
<tr><th></th><th>Item name</th><th colspan="2">Price</th><th>shipping</th></tr><th>Quantity</th>
</thead>
<tbody id= "cartbody">
</tbody>
</table>
</div>
</div>
Here is the ajax to send the userID to the server
$(function(){
$(".prod_buy").click(function(){
var htmlId = $(this).attr('id');
var idarray = htmlId.split('-');
var itemId = idarray[1];
$.ajax({
type: "POST",
url: "tempselector.php",
data: {'proId': itemId }
}).done(function( msg ) {
jQuery.parseJSON(msg);
var output = jQuery.parseJSON(msg);
var htmlstring;
alert ("im running");
for(var index=0;index<output.length; index++){
var itmnam = output[index][1];
var itmpic = output[index][2];
var itmpr = output[index][3];
var itmdisc = output[index][4];
var itmdesc = output[index][5];
var itmshp = output[index][6];
var itmav = output[index][7];
htmlstring +="<tr><th><img src = '../cartimg/'"+itmpic+"></th><td>"+itmnam+"</td><td>"+itmdisc+"</td><td>"+itmshp+"</td><td>QTY</td></tr>";
}
$('#cartbody').html(htmlstring);
$("#shpcart").fadeIn();
});
});
and here is the PHP to fetch the order of the passed user id
<?php
session_start();
include('includes/config.php');
$uId = $_SESSION["uId"];
$prID = mysqli_real_escape_string($link,$_POST["proId"]);
//$pQty = mysqli_real_escape_string($link,$_POST["prQTY"]);
$pQty = 2;
//$prID = 4;
$sqlget= "SELECT * FROM vasplus_programming_blog_pagination WHERE id='".$prID."'"; // to find the selected item
$resultget = mysqli_query($link, $sqlget);
$itemget = mysqli_fetch_array($resultget);
$itemId = $itemget[0]; // store the selected id in var
$itemNm = $itemget[1];
$ITimage = $itemget[2];
$ITprice = $itemget[3];
//$ITdiscount =$itemget[4];
$ITdescription =$itemget[5];
$ITshipping =$itemget[6];
// $ITavailable = $itemget[7];
$ITcontrycod =$itemget[8];
$itemCol = $itemget[9]; // store the selected color in var
$itemSiz = $itemget[10]; // store the selected size in var
$ITqty = $itemget[11];
// we need to search the temp table to see if the selected item is there
$sqlsrch= "SELECT * FROM XXXXX WHERE product_id ='".$prID."' AND size = '".$itemSiz."' AND color = '".$itemCol."' AND user_id = '".$uId."' "; // if the item is in the temp table or not
$resultsrch = mysqli_query($link, $sqlsrch);
$itemsrch = mysqli_fetch_array($resultsrch);
echo $itemsrch;
if (isset($itemsrch)){
$adqty = $itemsrch[8];
$adqty ++;
$sqlupdate=" UPDATE XXXXXX SET qty='".$adqty."' WHERE product_id ='".$prID."' AND size = '".$itemSiz."' AND color = '".$itemCol."' AND user_id = '".$uId."' "; // update the qty of theexisting items in temp table
$resultupdate = mysqli_query($link, $sqlupdate);
}else {
echo " user id searching ";
$sqlisUsr= "SELECT * FROM XXXXXX WHERE user_id = '".$uId."' "; // check if the user has any item in the temp table
$resultisUsr = mysqli_query($link, $sqlisUsr);
$isUsr = mysqli_fetch_array($resultisUsr);
if (isset($isUsr)){ // if user has items in the cart
$getOrdId = $isUsr[2]; // get the order ID
$sqladdN=" INSERT INTO XXXXXXx (order_id, user_id, photo, express, qty, unit_price, country, color, size, product_id) VALUES ('$getOrdId', '$uId' , '$ITimage' , '$ITshipping' , '$pQty', '$ITprice' , '$ITcontrycod' , '$itemCol' , '$itemSiz' , '$prID' ) "; // insert the item with the existing order ID
$resultaddN = mysqli_query($link, $sqladdN); }else{ // user has no record in temp order
echo " else is running " ;
$ReNth = 0;
$oId = 1;
while ($ReNth != 1){
$sqlNewOiD= "SELECT * FROM XXXXXX WHERE order_id = '".$oId."'"; // generate a new order ID
$resultOsrch = mysqli_query($link, $sqlNewOiD);
$oIdsrch = mysqli_fetch_array($resultOsrch);
if (isset($oIdsrch)){
echo $oId++;
echo " order Id generated " .$oId;
}else{ // insert the new item with the new order id in the temp table
echo $oId."oId<br />" ;
echo $uId."uId<br />" ;
echo $ITimage."<br />" ;
echo $ITshipping."<br />" ;
echo $pQty."<br />" ;
echo $ITprice."<br />" ;
echo $ITcontrycod."<br />" ;
echo $itemCol."<br />" ;
echo $itemSiz."<br />" ;
echo $prID."<br />" ;
$sqladdNOID = " INSERT INTO XXXXXx (order_id, user_id, photo, express, qty, unit_price, country, color, size, product_id) VALUES ('$oId', '$uId' , '$ITimage' , '$ITshipping' , '$pQty', '$ITprice' , '$ITcontrycod' , '$itemCol' , '$itemSiz' , '$prID' ) ";
$resultaddNOID = mysqli_query($link, $sqladdNOID);
$ReNth = 1; // quit the searching for unique order id loop
}//end if
}//end while
}// end if
}// end if
// pars json code for the cart
$sql= "SELECT * FROM XXXXX WHERE user_id = '".$uId."'" ;
$result = mysqli_query($link, $sql);
while($item = mysqli_fetch_array($result)){
$array[] = $item;
}
echo json_encode($array);
?>
The problem is that the ajax is not able to retrieve the parsed array by the PHP. I see that the $uId being passed to the PHP and the PHP code works fine and $array has been fetched, but in return the ajax isn't able to read the $array .
please help me here