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 6753729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:11:48+00:00 2026-05-26T13:11:48+00:00

I have a test script, that generate txt file with answers. And have 2

  • 0

I have a test script, that generate txt file with answers. And have 2 txt files with the correct answers. I want:
1) Unite all files in one table, like:

<table>
<tr>
<td>№ of question</td>
<td>data from file 1</td>
<td>data from file 2</td>
<td>data from file 3</td>
</tr>
...
</table>

2) I want to replace id in this files on text from DB (MySQL). I have table with question and answers with similar id (like in txt files).

All files have structure like:

1|3
2|4
3|1

where first number – is id of a question, and second is a variant of answer.

I start coding, but don’t know how to include data from files:

// Slect from DB
$qsel=mysql_query("SELECT `qid`, `qtext` from `questions` ORDER BY `qid`");

// Open file 1 
$key1=fopen("data/test_1_key1.txt", "r");
$k1=explode("/r/n", $key1);

// Open file 2 
$key2=fopen("data/test_1_key2.txt", "r");
$k2=explode("/r/n", $key2);

$rtable='<table border="1" cellspacing="0" cellpadding="3">
    <tr>
      <th width="40%">Q</th>
      <th width="20%">A 1</th>
      <th width="20%">A 2</th>
      <th width="20%">NAME</th>
    </tr>';
  while($q=mysql_fetch_row($qsel))
  {

    $rtable.='<tr><td><b>'.$q['1'].'</b></td>'; 
    $rtable.='<td>data from file 1</td>'; 
    $rtable.='<td>data from file 2</td>'; 
    $rtable.='<td></td>'; 
  }
  echo '</table>'.$rtable;
  • 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-26T13:11:49+00:00Added an answer on May 26, 2026 at 1:11 pm

    I would first fetch the textfiles and convert it into indexed array:

    $tmp1 = file('text1.txt');
    $data1 = array();
    foeach($tmp1 as $line)
    {
        list($key1, $val1) = explode("|", $line);
        $data1[$key1] = $val1;
    }
    

    and then, on mysql fetch loop, just use the indexed array:

    while($q=mysql_fetch_row($qsel))
    {
    
        $rtable.='<tr><td><b>'.$q['1'].'</b></td>'; 
        $rtable.='<td>' . ( isset( $data1[ $q['0'] ] ) ? $data1[ $q['0'] ] : '' ) . '</td>'; 
        $rtable.='<td>data from file 2</td>'; 
        $rtable.='<td></td>'; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so i have ruby script that simply writes to a test.txt file with hello
I have the following simple python test script that uses Suds to call a
I have a script that works fine on my test server (using IIS6). The
I have a simple test bash script which looks like that: #!/bin/bash cmd=rsync -rv
I have a test suite to perform smoke tests. I have all my script
I have a test suite to perform smoke tests. I have all my script
I have a script that scans all my servers in my domains and outputs
I have a css file that links to images. .test{ background: url(http://site.com/dynamic/test.jpg) no-repeat; }
I have created a script to run a test script on a batch of
I have a unix shell script which test ftp ports of multiple hosts listed

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.