Jump to content

Turning DB Records Into Links


Assorro

Recommended Posts

Greetings everyone. I started a project last weekend and I am looking for a community that is capable of helping me when I run into snags using php as I am quite new to it.

 

I have created a login system using MySql which allows members to register an account and the program by default places that account within a starting group. Registered members will be able to create their own group in the future which other members can switch to if they choose.

 

I realized last night that it is easy enough to list all the members within a group but I don't know how to turn those names into links so that when clicked, the members personal page is displayed. I want to study how to make the links so that they look like this:

 

http://www.somesite.com/members.php?user=someuser

I had the same problem with record paging. I just didn't know what it was called so I couldn't study it around the net. Is there a specific name used to refer to this? Thanks.

Link to comment
https://forums.phpfreaks.com/topic/149612-turning-db-records-into-links/
Share on other sites

Well, if you can make a list of usernames then making a list of links to user profiles is essentially the same.

 

Sort of like:

 

$db = new mysqli('localhost', 'user', 'password', 'database_name');

if ($result = $db->query('SELECT username FROM users WHERE user_id = 5')) {
echo '<ol>';
while($user = $result->fetch_assoc()) {
	echo '<li><a href="' . htmlentities(urlencode($user['username'])) . '">' . htmlentities($user['username']) . '</a></li>';
}
echo '</ol>';
}
else {
echo '<p>There are no users in this group.</p>';
}

Okay, keeping in mind that I am fresh out of the box with php I have a need to study everything from the grass roots up ... and I have a long way to go.

 

I plugged in the database info and ran the script as a standalone to study it but received "Fatal error: Class 'mysqli' not found in...."

 

My guess is that I have not defined parameters for mysqli but then again, I'm all at sea here. Thanks Daniel0.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.