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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:13:18+00:00 2026-05-24T00:13:18+00:00

ive got number of textboxes that will be filled in with name from database.

  • 0

ive got number of textboxes that will be filled in with name from database.

i create 5 textinputs, using for.. loop

for($i=1; $i<=5; $i++) {
  echo '<input type="text" value="">';
} 

my question is how do i enter the names to the each textboxes dynamically.

i tried:

$q = $db->query("SELECT * FROM att WHERE id_bs_res='$id_bs_res'");  

for($i=1; $i<=5; $i++) {
    while($r = $q->fetch_assoc()) {
        echo '<input type="text" value="'.$r['att_name'].'">';
    }
} 

if there are 3 names in database, it will only show 3 instead of 5 textboxes?
i want it shows all the textboxes even if the rest of textboxes will be blank.

sample textboxes
1. names
2. names
3. names
4. ------
5. ------
  • 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-24T00:13:19+00:00Added an answer on May 24, 2026 at 12:13 am

    remove the inner while loop.

    $q = $db->query("SELECT * FROM att WHERE id_bs_res='$id_bs_res'");  
    
    for($i=1; $i<=5; $i++) {
        $r = $q->fetch_assoc();
        echo '<input type="text" value="'.isset($r['att_name'])?$r['att_name']:''.'">';
    }
    

    of course, better check count of the returned rows, and do not call fetch_assoc() after you’ve displayed the 3 rows, just output the next 2

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

Sidebar

Related Questions

Ive got an assignment to create an image gallery using flickr - this has
I've got a number (3232251030) that needs to be translated from Decimal to Binary.
I've got a number of non-technical users that all share a set of project
I've got WPF 4 app that has a number of UserControls that share styles
i've got a table like that : Article Number Last Voucher Number Last Voucher
I've got a relatively large .Net system that consists of a number of different
I've got a spreadsheet with two columns that represent the number of processed records,
Ive got a problem, Im using jquery for my googlemaps thingy Im doin and
I've got a number that needs to be compared against 3 character strings. The
Currently ive got some reference counted classes using the following: class RefCounted { public:

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.