Jump to content

dav

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by dav

  1. Hello, I have run into an issue with what i think might be special characters. Basically I have expanded on the W3 Web Tutorial. http://www.w3schools.com/website/web_spa_daas.asp

    I have a PhP file that successfully retrieves data form a MySql database (I call the PhP file directly from my browser and it displays the data in the correct format etc)

    When i then attempt to display the data in an HTML table (of the called upon PhP file ^mentioned above) it fails to display.

    I am pretty sure that the issue is that in several fields of the PhP query the data contains "[" and "]". Because when i remove those specific fields form the query it does display properly in the HTML table.

    I do WANT to display the data sets as they are including the "[" and "]" as it is critical to my end goal. (editing the data sets from the HTML table/form).

    I have googled and read a ton of article/blogs/tutorials with no luck on this exact issue.I did find one article that suggested all Char-Sets be set the same and that it be UTF-8 and that it be declared on all files/databases etc, so i have checked that they all do/are.

     

    example PhP file.... (the "Item", "Buy", and "Sell" fields each contain as part of the data "[" and "]" ) if i remove these three fields it works perfectly, but obviously i need them displayed.

     

    <?phpheader("Access-Control-Allow-Origin: *");header("Content-Type: application/json; charset=UTF-8");$servername = "127.0.0.1";$username = "root";$password = "";$dbname = "xdoadayzepoch";$conn = new mysqli($servername, $username, $password, $dbname);$result = $conn->query("SELECT ID, Qty, Item, Orders, Buy, Sell, Tid, Afile FROM Traders_Data");$outp = "[";while($rs = $result->fetch_array(MYSQLI_ASSOC)) {    if ($outp != "[") {$outp .= ",";}    $outp .= '{"ID":"'. $rs["ID"]. '",';$outp .= '"Item":"'. $rs["Item"]. '",';    $outp .= '"Qty":"'. $rs["Qty"]. '",';	$outp .= '"Buy":"'. $rs["Buy"]. '",';	$outp .= '"Sell":"'. $rs["Sell"]. '",';	$outp .= '"Orders":"'. $rs["Orders"]. '",';	$outp .= '"Tid":"'. $rs["Tid"]. '",';    $outp .= '"Afile":"'. $rs["Afile"]. '"}';}$outp .="]";$conn->close();echo($outp);?>
    example of returned data from above, when called directly from browser....
    [{"ID":"4996","Item":"["Skin_CZ_Special_Forces_GL_DES_EP1_DZ",1]","Qty":"10","Buy":"[2,"ItemGoldBar",1]","Sell":"[1,"ItemGoldBar",1]","Orders":"0","Tid":"476","Afile":"trade_items"},{"ID":"4999","Item":"["Skin_Drake_Light_DZ",1]","Qty":"10","Buy":"[2,"ItemGoldBar",1]","Sell":"[1,"ItemGoldBar",1]","Orders":"0","Tid":"476","Afile":"trade_items"},{"ID":"5002","Item":"["Skin_Soldier_Sniper_PMC_DZ",1]","Qty":"10","Buy":"[2,"ItemGoldBar",1]","Sell":"[1,"ItemGoldBar",1]","Orders":"0","Tid":"476","Afile":"trade_items"},{"ID":"5003","Item":"["Skin_FR_OHara_DZ",1]","Qty":"10","Buy":"[2,"ItemGoldBar",1]","Sell":"[1,"ItemGoldBar",1]","Orders":"0","Tid":"476","Afile":"trade_items"}]

    HTML code to display above returned data in a table....

    <!DOCTYPE html><html><head>	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	<title>[DoA]DayZ</title>	<link href="Site.css" rel="stylesheet"></head><body><nav id="nav01"></nav><div id="main">	<h1>[DoA]DayZ Server Db - Trader Tids</h1><div id="id01"></div><footer id="foot01"></footer></div><script src="Script.js"></script><script>var xmlhttp = new XMLHttpRequest();var url = "http://127.0.0.1/[DoA]DayZ/datafetch/fetch_tradersdata.php";xmlhttp.onreadystatechange=function() {    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {        myFunction(xmlhttp.responseText);    }}xmlhttp.open("GET", url, true);xmlhttp.send();function myFunction(response) {    var arr = JSON.parse(response);    var i;    var out = "<table><tr><th>ID</th><th>Item</th><th>Qty</th><th>Buy</th><th>Sell</th><th>Orders</th><th>Tid</th><th>Afile</th></tr>";    for(i = 0; i < arr.length; i++) {        out += "<tr><td>" +         arr[i].ID +        "</td><td>" +		arr[i].Item +        "</td><td>" +		arr[i].Qty +        "</td><td>" +		arr[i].Buy +        "</td><td>" +		arr[i].Sell +        "</td><td>" +		arr[i].Orders +        "</td><td>" +		arr[i].Tid +        "</td><td>" +        arr[i].Afile +        "</td></tr>";    }    out += "</table>"    document.getElementById("id01").innerHTML = out;}</script></body></html>

    the above HTML fails to display the table with the returned data, it actually displays nothing, UNLESS i remove the three fields from the whole process (that contain the "[" and "]" character).

    So My Questions is, how do i get the table to display with the "[" and "]" in their respective fields?

×
×
  • Create New...