Jump to content

webguync

Members
  • Posts

    951
  • Joined

  • Last visited

Everything posted by webguync

  1. I fully understand now and have this working as intended. Thanks.
  2. Sorry to not understand fully, but what am I doing wrong here? $outp = ["records" => []]; while($rs = $result->fetch_array(MYSQLI_ASSOC)) { if ($outp != "") {$outp .= "";} $outp .= '{"Portrait":"' . $rs["Portrait"] . '",'; $outp .= '"First Name":"' . $rs["FName"] . '",'; $outp .= '"Last Name":"' . $rs["LName"] . '",'; $outp .= '"DOI":"'. $rs["DOI"] . '",'; $outp .= '"MOI":"'. $rs["MOI"] . '",'; $outp .= '"YOI":"'. $rs["YOI"] . '",'; $outp .= '"ID":"'. $rs["id"] . '"}'; } $outp ='{"records":['.$outp.']}'; $conn->close(); echo json_encode($outp); I get an error with this line $outp = ["records" => []]; Parse error: syntax error, unexpected '[' in Database-search/DB-Search.php on line 7
  3. o.k, I will try it that way. Thx.
  4. $outp = ""; while($rs = $result->fetch_array(MYSQLI_ASSOC)) { if ($outp != "") {$outp .= "";} $outp .= '{"Portrait":"' . $rs["Portrait"] . '",'; $outp .= '"First Name":"' . $rs["FName"] . '",'; $outp .= '"Last Name":"' . $rs["LName"] . '",'; $outp .= '"DOI":"'. $rs["DOI"] . '",'; $outp .= '"MOI":"'. $rs["MOI"] . '",'; $outp .= '"YOI":"'. $rs["YOI"] . '",'; $outp .= '"ID":"'. $rs["id"] . '"}'; } $outp ='{"records":['.$outp.']}'; Hi for the above PHP code the output looks like this JSON format { "records": [{ "Portrait": "image1.png", "First Name": "Dave", "Last Name": "Smith", "DOI": "20", "MOI": "0", "YOI": "2017", "ID": "1" } { "Portrait": "image2.png", "First Name": "Sally", "Last Name": "Jones", "DOI": "20", "MOI": "0", "YOI": "2009", "ID": "2" }] } and this doesn't validate because there should be comma in between records like this: { "records": [{ "Portrait": "image1.png", "First Name": "Dave", "Last Name": "Smith", "DOI": "20", "MOI": "0", "YOI": "2017", "ID": "1" }, { "Portrait": "image2.png", "First Name": "Sally", "Last Name": "Jones", "DOI": "20", "MOI": "0", "YOI": "2009", "ID": "2" }] } I am trying to figure out how to get a comma added between records without also adding it at the end, b/c that is invalid also. Any ideas?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.