melting_dog Posted August 24, 2012 Share Posted August 24, 2012 Hi all, I am trying to figure out a way to make a JSON script more dynamic and responsive to a database. I am forming and idea in my head and just wanted to run it past people here - not expecting any coding answers just want to know if it is possible. Use PHP to query the DB and create some vars, Write the vars to a txt file adding in the necessary JSON brackets, Use PHP's JSON Encode to encode the txt file to JSON Repeat when ever the database is updated What do you guys think? Is this a plausible scenario? Quote Link to comment https://forums.phpfreaks.com/topic/267515-use-php-to-update-a-txt-doc-then-convert-doc-to-json/ Share on other sites More sharing options...
Christian F. Posted August 24, 2012 Share Posted August 24, 2012 Besides step 2 being completely unnecessary, and even detrimental, I'm struggling to figure out why you want to do this? Why not just have the PHP script pull the data from the database at request time, encode it and send it directly to the requesting source? Keep it simple, and you'll have less troubles with writing the code as well as maintaining it. Not to mention that you can't get more responsive than pulling it from the database at request time. PS: JSON isn't a script, it's a data format. I'm assuming you're referring to a JavaScript, that expects to receive the data in the JSON format. Quote Link to comment https://forums.phpfreaks.com/topic/267515-use-php-to-update-a-txt-doc-then-convert-doc-to-json/#findComment-1372155 Share on other sites More sharing options...
ManiacDan Posted August 24, 2012 Share Posted August 24, 2012 Use PHP to query the DB and create some vars, Write the vars to a txt file adding in the necessary JSON brackets, Use PHP's JSON Encode to encode the txt file to JSON Repeat when ever the database is updated But...why? Why not make a PHP page that spits out a json-formatted document from the database every time you call it? Why all these extra steps? Quote Link to comment https://forums.phpfreaks.com/topic/267515-use-php-to-update-a-txt-doc-then-convert-doc-to-json/#findComment-1372167 Share on other sites More sharing options...
melting_dog Posted August 25, 2012 Author Share Posted August 25, 2012 Use PHP to query the DB and create some vars, Write the vars to a txt file adding in the necessary JSON brackets, Use PHP's JSON Encode to encode the txt file to JSON Repeat when ever the database is updated But...why? Why not make a PHP page that spits out a json-formatted document from the database every time you call it? Why all these extra steps? Thanks for the response! And to answer your question of why: because I am trying to learn the best way of approaching this. Are you suggesting using the having my JavaScript read directly from the .php file using JSONencode? Quote Link to comment https://forums.phpfreaks.com/topic/267515-use-php-to-update-a-txt-doc-then-convert-doc-to-json/#findComment-1372297 Share on other sites More sharing options...
trq Posted August 25, 2012 Share Posted August 25, 2012 because I am trying to learn the best way of approaching this. Approaching what? You haven't told us what your trying to do, you've simply told us how your planning on doing it, and your how sounds very convoluted and unnecessary. Quote Link to comment https://forums.phpfreaks.com/topic/267515-use-php-to-update-a-txt-doc-then-convert-doc-to-json/#findComment-1372298 Share on other sites More sharing options...
ManiacDan Posted August 25, 2012 Share Posted August 25, 2012 because I am trying to learn the best way of approaching this.As thorpe said, you haven't told us what "this" is. But I think it's safe to say that you're not doing it right if you're trying to make a flat file on your filesystem, you're not doing it right. Are you suggesting using the having my JavaScript read directly from the .php file using JSONencode?That's how it's done, yes. Quote Link to comment https://forums.phpfreaks.com/topic/267515-use-php-to-update-a-txt-doc-then-convert-doc-to-json/#findComment-1372319 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.