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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:46:26+00:00 2026-05-22T02:46:26+00:00

I have a database named teste with a table called exemplo with 2 columns

  • 0

I have a database named teste with a table called exemplo with 2 columns (id, nome):
Want a php script to select all the information in the nome column, and echo that information and place them in a txt file. What’s wrong in the code?
I can only see the first value and not the second.. And with an infinite loop!

$link = mysql_connect('localhost', 'root', '123');
if (!$link) {
  die('Could not connect: ' . mysql_error());
}

mysql_select_db('teste', $link);

/* Desired */
$file = fopen("myfile.txt","w");

$result = mysql_query("SELECT * FROM exemplo");
$array = mysql_fetch_array($result);
while ($array) {
  echo $array['nome'];

  fputs($file ,$array['nome']); 
}

mysql_close($link);
  • 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-22T02:46:27+00:00Added an answer on May 22, 2026 at 2:46 am

    That’s because mysql_fetch_array only returns one result at a time, so $array is always true. You want this:

    while ($array = mysql_fetch_array($result)) {
      echo $array['nome'];
      fputs($file ,$array['nome']); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table named call with columns call_time, location, emergency_type and there
I Have a DataBase in my project With Table named 'ProcessData' and columns named
I have a Database (SQL Server) with table named 'ProcessData' and columns named 'Process_Name'
I have a table in my Postgres database with columns named type, desc, and
Suppose I have a table called 'test', into which there are three columns named
I have a database table (named Topics) which includes these fields : topicId name
I have some columns in a few tables in my database that are all
I have a table called products in a MySQL database. products looks some what
In the database, I have a table called Contact. The first name and other
I have a Database named CarsType.accdb there are four fields in the data base

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.