Display query results using hyperlink? [solved]

Hi again :slight_smile:

I’ll explain what I want to do and if someone could point me in the right direction it would be most appreciated.

I have a member table in my mysql database with all the usual, username, name, date joined etc. What I’d like to do is create a member profile page that is reached by clicking on a member’s name.

I’m not sure how to make the clickable link of the member’s name a variable.

I think i’ve got the query for the information I want displayed sorted out but I’m at a bit of a loss. as to how to get that information to the page once a user clicks.

This is what I have so far for the query…

[php]

<?php include ("misc.inc"); $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $selected = /*this is where I'm stuck*/ $sql = "SELECT DISTINCT loginName FROM Member WHERE loginName='$selected'"; $result = mysql_query($sql) or die("Couldn't execute query 1."); while ($row = mysql_fetch_array($result)) { extract ($row); echo "{$row['loginName']}.
"; } ?>

[/php]

Could someone give me a rundown on the steps I need to take to achieve this? Once I have some idea of what I’m supposed to be doing, I’'m sure i’ll be able to figure it out.

I’m just not sure I’m going in the right direction. :)

Thanks again, NightOwl

I think I would take the member login name and add it to the URL (you know that ?user=username thing) so that becomes available to the next page as a $_GET variable. You can then have the next page do a query getting all of the users info and displaying it.

Make sense?

Thanks lig,

I think that’s what I want to do. lol *shrugs

I’m pretty new to php and slowly getting there. The book I’ve been using explains how to get the variable from a form using $_POST (or $_GET)and I think I’ve figured that out ok, but doesn’t go into much detail about using a url in order to do it.

I’ve been searching the net for some tutorials that explain it better though haven’t found one as yet.

I’ll keep looking and when I come up with a solution I’ll post it here.

You’ve pointed me in the right direction though and that definately helps! ;)

*slaps forehead.

It just hit me…

Use the variable from the users membername when they login, in the hyperlink. (feels silly, lol, that’s what you said right lig?)

Otherwise any other links would probably be the result of a search and I’d use that as the variable. Sound right?

Ok, heading off to plug away at that and to figure out how to use the url.

Be back in a day or so :D

<?php
$user = $_POST['user'] /// gotten from a form on another page
// create links that allow the user name to be accessable with the $_GET
?>
<span class='style14'>
<a href='member_page.php?user = "<?php echo $user; ?>"><?php echo $user; ?></a>
</span> 
<BR>

Thanks for that :)

I’m getting there. Got the hyperlink to take me to the right place using tags, now I need to work on the code I’m doing so it displays the right information.

Will post how I went about it when I get it done:)

ok, I did it!

I’ll explain step by step…

If a user has logged in their name appears on the page. I then made that a hyperlink to their profile page.

[php]

<?php session_start(); /* If logged in provide a link with their user name at the top of the page.*/ if ($_SESSION['auth'] == "yes") { include ("misc.inc"); $connection = mysql_connect($host, $user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql = "SELECT loginName FROM Member WHERE loginName='{$_SESSION['logname']}'"; $result = mysql_query($sql) or die("Couldn't execute query 1."); $row = mysql_fetch_array($result,MYSQL_ASSOC); extract($row); } ?>

/link within the html of the page/

<?Php echo $loginName;?>

[/php]

On the profile page I used $_GET to access the username.

[php]

<?php /* Program: member_proflie.php * Desc: Displays the member profile page. Shows public information * of the user. */ session_start(); /*check if logged in*/ if (@$_SESSION['auth'] != "yes") { header("Location: login.php"); exit(); } include("CCheader.inc"); ?> <?php /* get username and information*/ $user = $_GET['$loginName']; include("misc.inc"); $connection = mysql_connect($host, $user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $sql = "SELECT * FROM Member WHERE loginName='$loginName'"; $result = mysql_query($sql) or die("Couldn't execute query 1."); $row = mysql_fetch_array($result,MYSQL_ASSOC); $sql2 = "SELECT loginTime FROM Login WHERE loginName='$loginName'"; $result2 = mysql_query($sql2) or die("Couldn't execute query 2."); $row2 = mysql_fetch_array($result2,MYSQL_ASSOC); include ("member_profile_Form.inc"); /*html for the member profile.*/ ?>

/code within member_profile_Form.inc/

<?php echo $row['loginName']; ?> <?php echo $row['firstName']; ?> <?php echo $row['lastName']; ?>

<?php echo $row2['loginTime']; ?>

[/php]

It took a bit of trial and error and I had a few problems figuring out the mysql_fetch_array but eventually I got there:)

If anyone can see a better way to do it I’d love to hear it.

Thankyou everyone for your help :D

Sponsor our Newsletter | Privacy Policy | Terms of Service