Hi I had a community web site and I need to show "Recent Visitors" under a profile ( just like in Orkut ) I do it successfully and that will show in the page like this ...
Name1, Name2 , Name3 ..
But I need to make link in each name. like

<a href="profile.php?userid=name1">Name1</a>

Please help me.. How can I do it with MySql and php...


Thanks
rajeesh

Member Avatar

diafol

Get a list of your most recent visitors from your DB. I take it that you log page hits and store the login info in a table.

Use the LIMIT clause to restrict the number you want to retrieve and the ORDER BY ... DESC clause to order the visitors (starting with most recent).

Your MySQL DB should have a Users table (or something similar) and some other table logging activity. The 'Activity' table or whatever it's called should have a column called user_id or something similar.

You will need to create an INNER JOIN clause to get the user particulars. Your query should look something like this:

SELECT users.username FROM users INNER JOIN activity ON users.user_id = activity.user_id ORDER BY activity.last_impression DESC LIMIT 10

Where last_impression is a unix datestamp or datetime field.

Once retrieved, just loop through the recordset:

echo "\n<a href=\"yourpage.php?profile={$username}\" >{$username}</a>";

Wouldn't you want to make use of the while(); function?

Assuming your query returns the id and username:

<?

while($online = mysql_fetch_assoc($query) {
echo "<a href='/profile.php?'" . $online[id] . "'>" . $online[username] . "</a>";

?>
Member Avatar

diafol

I suggested it:

Once retrieved, just loop through the recordset:

echo "\n<a href=\"yourpage.php?profile={$username}\" >{$username}</a>";

Missed where you suggested loop, just saw code. Oops. (I fail for scanning through, I guess.)

:-p