Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:26:13+00:00 2026-06-02T02:26:13+00:00

(This question is following on from my previous problem which has been fixed (Here)

  • 0

(This question is following on from my previous problem which has been fixed (Here)

I found a similar question to this (Here) but the solution wasn’t quite what I was looking for.

I currently have a JQuery styled autocomplete search engine on my site, called (fcbkcomplete). The original operation of the script ran from a .txt file, looked up the manually-entered values and outputted them in the autocomplete results. However, I want the script to get the values from a MYSQL database instead of being manually entered into a .txt file as I eventually want the user to have the option of adding their own values.

I have therefore made the Javascript call a .php file instead of .txt with this script in it:

//connection details

$getData = mysql_query("SELECT Name FROM tblIngredient"); 

 while($info = mysql_fetch_array($getData)) 
 {
     echo "{\"key: value:\";
     echo $info['Name'];
     echo "key: value:\"";
     echo $info['Name'];
     echo "}, ";
 }

This script works and outputs the data in the correct format:

{"key": "vodka","value": "vodka"}, {"key": "tequila","value": "tequila"},

So I need to know how I then convert this JSON output into data.txt (so as the database table grows, the .txt file is updated automatically when the script is run)

This is the final step in the search on my site so any help is much appreciated.

-Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:26:15+00:00Added an answer on June 2, 2026 at 2:26 am

    I can’t really tell which bit of data you want to save to this txt file but I’m going to assume it’s this:

    {"key": "vodka","value": "vodka"}, {"key": "tequila","value": "tequila"},
    

    If it isn’t you can just substitute it for what you want.

    I think the function you are looking for is fopen() specifically using ‘a’ as the second argument.

    From the manual:

    ‘a’ Open for writing only; place the file pointer at the end of the file.
    If the file does not exist, attempt to create it.

    Here’s an example (a very brief one at that) of how to use it.

    $string = '{"key": "vodka","value": "vodka"}, {"key": "tequila","value": "tequila"}';
    $fp = fopen('somefile.txt', 'a');
    fwrite($fp, $string);
    fclose($fp);
    

    One thing to consider here (amongst others) is the file will need the proper permissions for write access.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem follows on from a previous question . When I run the following
Following on from a previous question, ( previous question here ), the problem I'm
Okay, this is following on from my previous question reguarding performing a simple ajax
I realise this question has been asked before however the previous answers have gotten
Following on from my previous question , which was so quickly answered by Meder
Following on from my previous question [link text][1] , I have a new problem.
Following my previous question , in which I think I've narrowed my problem down
Following on from my previous question I have been working on getting my object
This question is overflow from the following question: How do I programmatically convert mp3
This question comes from my experience with the following question: https://stackoverflow.com/questions/492748/new-responses-icon-on-so-crashes-ie7-closed In that question,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.