Skip to content
Advertisement

How to display data inside a single form from database

I am trying to display data from database inside single input form. Let’s say I have 3 rows with column called name.

JavaScript

This is how I am getting the rows:

JavaScript

So how do i display the data in one input form instead of three? like in the picture attached. enter image description here

Advertisement

Answer

When you are doing this:

JavaScript

You are essentially creating as many input lines as the loop iterates. Instead you should do this:

JavaScript

And now we have a nice $userNames array that we shall implode and put in our input line:

JavaScript

Don’t use while loops to create the form itself… use them to setup the data….

When creating tables or select form data and such using loops is a good idea if you understand what is going on inside the loop 🙂

There are many more ways to go on this…

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement