Jump to content

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.

You can use the old mysql extension instead of the new mysqli (MySQL improved) if you wish. You'll also have to modify the query to fit your needs. It was a sample snippet and not supposed to be used verbatim. You'll also have to do error handling and such.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.