I have a list from a database of email address, name, ID etc...
I need to be able to tick a box on the list, by each row, hit one button and the next page shows specific details of each user, in a row of its own.
ie.
Joe Bloggs
ID 4
email@email.com
address1
address2
address3
I suspect it'll be just gathering the ID from the db and then doing a SELECT * on the next page, but how do I gather all the IDs from the list page, and have it run a search on the next page via an Array?
Thanks in advance.
Using Array to gather multiple details into one page
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Using Array to gather multiple details into one page
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Using Array to gather multiple details into one page
im assuming the rows in which your talking about are basic information on each user. (id, name)
You would first generate an entire list using the sql:
First you would obviously need to connect to your database to generate your initial list of people, along with a checkbox input field in order to select which users will be displayed in more detail. Rather than use name="selectedUsers" we use name="selectedUsers[]" which converts all the selected fields value's into an array and submits it through POST as the array 'selectedUsers'.
Your list would look something like this:
Using PHP we can then grab all the stored userID's from 'selectedUsers' and run through the array executing an individual query per person.
Then on your following page after you submit each checked user:
something similar to this I think should achieve what your after.
You would first generate an entire list using the sql:
Code: Select all
$query = "SELECT `userID`,`user_name` FROM `users_table`";Your list would look something like this:
Code: Select all
$result = mysql_query($query,$dbConnection);
while($row = mysql_fetch_assoc($result)){
print "<input type='checkbox' name='selectedUsers[]' value='{$row['userID']}' />{$row['user_name']}<br/>";
}
Then on your following page after you submit each checked user:
Code: Select all
$idArr = $_POST['selectedUsers']
foreach($idArr as $userID){
$query = "SELECT * FROM `users_table` WHERE `userID` = '{$userID}'";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
print "ID: {$row['userID']} ||Name: {$row['user_name']} ||Email {$row['email_address']}";
}