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

  • SEARCH
  • Home
  • 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 7533693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:47:52+00:00 2026-05-30T05:47:52+00:00

I am attempting to write the results from an SQL query into text files.

  • 0

I am attempting to write the results from an SQL query into text files. Write works fine however i want to be able to write all entries for the first time at once and subsequently add
all entries that aren’t already in the file. Please do you know how this can be achieved?

  $t = mysql_query("SELECT text FROM transactions")
      or die("SELECT Error: ".mysql_error());


print "<table width=300 border=1>\n";
while ($get_info = mysql_fetch_row($t)){

$class = $op->classify($field); 

print "<tr>\n";
print "\t<td>Transaction</td>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
print "\t<td>Type</td>\n";
foreach ($get_info as $field)
print "\t<td>$class</td>\n";
print "</tr>\n";


if ($class == "pos")
{
$filep = "positive.txt"; 
$handlep = fopen($filep, 'a');
$data = "$field\n";
fwrite($handlep, $data);

fclose($handlep); 


}
if ($class == "neg") {

$filen = "negative.txt"; 
$handlen = fopen($filen, 'a');
$datan = "$field\n";
fwrite($handlen, $datan);

fclose($handlen);

}
  • 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-05-30T05:47:55+00:00Added an answer on May 30, 2026 at 5:47 am

    first, i can’t imagine why you would ever want to do this, but here is how I would do it.

    with each record, also store a timestamp in one of the columns. whenever you query the DB for new records to write, you do a query that only grabs records whose timestamps are later than the flat file’s last modification time. the flat file of course being the file that you are doing the writes to.

    you can use a simple filemtime($filename) to get your file’s last modification time.

    http://php.net/manual/en/function.filemtime.php

    you might want to get a lock on the file before appending to it as well depending on how these writes are triggered.

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

Sidebar

Related Questions

I am attempting to read the results from a SQL query into a List(Of)
I apologize for the vague title. I am attempting to write a query that
I'm attempting to write a linq query which uses several tables of related data
We are attempting to concatenate possibly thousands of rows of text in SQL with
All, I'm attempting to write what should be simple validation for a Struts2 action.
Writing and reading from LocalStorage is working fine from my popup and tab. However,
I am attempting to translate or convert these functions from a .asp file into
I'm attempting to write a function that recursively computes the resulting fibonacci number from
I've been attempting to write a Lisp macro that would perfom the equivalent of
I am attempting to write an application that uses libCurl to post soap requests

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.