Pull contents from database, but for each row?

All righty.

This may seem a little hard to understand, but I have a table. This table is currently empty but I want to know how to make it so after it connects to my database it pulls each user based on ID and displays all there info for… Well, quick access. But I dont know how to make it so that for each user it displays the info correctly. Any idea on how to do this.

Still confused on what im trying to do?

Lets say I have 3 members in my database, I want it to go through, and make a table, on this page with the 3 members info. (E-Mail, Username, Etc). And it will pull each members info.

Members:
[table]
[tr]
[td]User 1[/td]
[/tr]
[tr]
[td]User 2[/td]
[/tr]
[tr]
[td]User 3[/td]
[/tr]
[/table]

Thanks for any help, -Improvizionz

  1. You connect to the database
  2. You run a query on said database
  3. You read the answer from the database
  4. You present the result in an HTML table

That doesnt really help me, I know how to connect, I know how run queries to the database and all, but now the number of users can change so I want it so that each one gets its own row with all its info displayed, I dont know how to do this. Can anyone help with an exact code or anything?

Well, normally, you would have a table for your users and in that table you would have all of the info you need.
Such as, UserID, Password, UserName, EmailAddress, Phone, and whatever else you want.

Then, you have them log-in. When, they log in and are validated with the correct user name and password,
you would pull the rest of the info from your database and display it.

Is that info what you wanted?

Sorry, perhaps I wasnt clear, I have an Admin Panel, and inside the members section, I want it to pull each users stuff. Not inside the Database I want tables, I want HTML tables, but I want to know how to pull data from the database, and for each “ID” it displays the following info in the row. :slight_smile:

Thanks for trying to help.

Well, I thought I was clear on that. You have a database with the info on each user.
The data is something like ID, UserName, UserPassword, emailAddress, etc…
You start your table for the “members” section of the ADMIN. You query the database sorted by ID.
That gives you a recordset of the members with all their data. You while thru that
and display it into your table. Did that make sense to you? In the recordset, you parse it by rows.
Each row is the entire data for one member. You just put these into cells in one row.

Hope that helps some…

Lol. Not really, im kinda new to PHP and dont know everything about it, so I have no idea what a ‘recordset’ is in PHP. :L

Well, basically a recordset is the results of a query to database. It is a “set” of records…
Here is one way to build a table. Note: this is based on my comments, not your actual database.
The “while” loops thru each line of user data in the database. The “foreach” loops thru each item in the row.

[php]

<?PHP // Set up your connection to your database... echo ""; // Start table... // Next line is the first line of table that creates the titles for each col... (Only a few samples shown!) echo ""; // Process a query to pull all of the user data $conn = mysql_connect( $hostname, $username, $password ); @mysql_select_db($dbname); $query="SELECT * FROM Users"; $results = mysql_query ( $query, $conn); // Now we have all of the users and their data in our $results array... // loop through the results, creating rows in the table while( $row = mysql_fetch_row($results) ) { echo ""; foreach($row as $cell) //Display all data in this row of user data... echo ""; echo "\n"; } echo "
ID User Name User Password Email-Address
$cell
"; // End table... mysql_close($conn); // Close database connection... ?>

[/php]
Note: $hostname, $username, $password, $dbname are variables for these items that you have to fill.
And, you will need to fill in the headers of the table. I just put a few samples in it for you! Good luck…

Oh my god!

Thank you so much, this is exactly what I have been looking for!

Also, I knew the database connect stuff, but thanks anyways.

-Improvizionz

Very glad to help you! It’s always a nice fuzzy feeling to solve a programming project!

Glad I could help, come back with the next section’s problem…

CYA in the bitstream!!!

Sponsor our Newsletter | Privacy Policy | Terms of Service