I would like to make a page for my website where people can see all the other member profile. I have a have a mysql db created where all the user's info are located. How can I generate a page where all the name of the users are listed?
Thanks,
Andrei
how to generate a page with an entire collumn from a db
Moderator: General Moderators
-
andrei.mita
- Forum Commoner
- Posts: 65
- Joined: Sun May 08, 2005 4:06 am
- Location: Barlad/Romania
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
if (!isset($_GET['user_id']))
{
$result = mysql_query("SELECT * FROM `users_table` ORDER BY `user_id`") or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<a href="?user_id='.$row['id'].'>'.$row['user_name'].'</a> <br />';
}
}
else
{
$result = mysql_query("SELECT * FROM `users_table` WHERE `user_id` = '".$_GET['user_id']."' LIMIT 1") or die(mysql_error());
if mysql_num_rows($result) == 0)
{
echo 'No User Found';
}
else
{
//do whatever with the user information
print_r($row);
}
}Thats about as basic as you can get. This will output all the members in your users table, if you click on their name it will display only their information. I also recommend you do a quick search on "sanitation" because your query can be altered because no filtering is being done on $_GET['user_id'].. some features that may be of use are: mysql_escape_real_string, preg_match
-
andrei.mita
- Forum Commoner
- Posts: 65
- Joined: Sun May 08, 2005 4:06 am
- Location: Barlad/Romania
I have a little problem implementing the code. I establish the connection to the mysql server, I choos the the db and then... i post the code.
the means that you don't have to do nothin in order for the script to run, no? You don't have to push anything, right?
Thanks,
Andrei
the
Code: Select all
if (!isset($_GETї'user_id'])Thanks,
Andrei
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
What jcart did was create a script for you that could also another question for you.
the first if statement is used to get all the rows from the db for you.
the else statement will be used if you decide to do a search for just a particular person based on their id.
two birds with one stone and all that.
the first if statement is used to get all the rows from the db for you.
the else statement will be used if you decide to do a search for just a particular person based on their id.
two birds with one stone and all that.