troubleshooting Question

Json - How do remove chars from a json qry output

Avatar of justmelat
justmelat asked on
JavaScriptPHPScripting Languages
1 Comment1 Solution281 ViewsLast Modified:
I had a previous issue that several people suggested I use json to resolve.  Was not familiar with it nor was the js programmer an expert with it, so I didn't pursue it  with a previous project.  I have started working with json a bit and found an issues I can't resolve:

I am using  code like this to spit about and array of data:
<?php
 $requiredFieldsArray = array();
    $results = mysql_query("select account_id, display_name, id from field 
where account_id = $holdAcctID and required_flag = 1");
    while($result = mysql_fetch_assoc($results)) 
        {
        $requiredFieldsArray[] = $result;
    }
?>
<script language="javascript">
    var requiredFieldsPRS = <?php echo "new Array(". json_encode($requiredFieldsArray).")"; ?>;
</script>
}

It outputs this:
 var requiedFieldsPRS = new Array([{"account_id":"3","display_name":"Project Requested By","id":"15"},{"account_id":"3","display_name":"Project Title","id":"18"},{"account_id":"3","display_name":"Project Type","id":"19"},{"account_id":"3","display_name":"Banner Details","id":"20"},{"account_id":"3","display_name":"Email to Me","id":"2910"}]);;

In my code how can I remove the "[" and "]" from the beginning and end of the array, so it will appear like this?
 var requiedFieldsPRS = new Array({"account_id":"3","display_name":"Project Requested By","id":"15"},{"account_id":"3","display_name":"Project Title","id":"18"},{"account_id":"3","display_name":"Project Type","id":"19"},{"account_id":"3","display_name":"Banner Details","id":"20"},{"account_id":"3","display_name":"Email to Me","id":"2910"});
Note: The opening and closing brackets are gone in the above output.
ASKER CERTIFIED SOLUTION
leakim971
Multitechnician
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros