Zhyrios Posted March 21, 2012 Share Posted March 21, 2012 Hey i'm having trouble figuring out how to do this. This is the code grabbing the users who are online and listing them one by one. $qt=mysql_query("SELECT username FROM users WHERE lastvisit > '$tm' and online='ON'"); echo mysql_error(); while($nt=mysql_fetch_array($qt)){ echo "<tr><td> $nt[username] </td></tr>"; } ?> what i want to do is have each username be a hyperlink that links to their profile how would i go about this? cause i'm completely clueless on this. is there some way i can do it in the php or will i need to make a varchar column for each player that holds their profile link and grab that with the query too? Link to comment https://forums.phpfreaks.com/topic/259399-turning-each-array-value-into-a-link/ Share on other sites More sharing options...
trq Posted March 21, 2012 Share Posted March 21, 2012 if ($result =mysql_query("SELECT id, username FROM users WHERE lastvisit > '$tm' and online='ON'")) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)){ echo "<tr><td><a href=\"profile.php?id={$row['id']}\">$row['username']</td></tr>"; } } } ?> Then on profile.php have a query that uses the value passed in through $_GET['id'] to that gets a users details. Link to comment https://forums.phpfreaks.com/topic/259399-turning-each-array-value-into-a-link/#findComment-1329751 Share on other sites More sharing options...
Muddy_Funster Posted March 21, 2012 Share Posted March 21, 2012 I assume that you will be linking to a profile page (call it profile.php for sake of argument). Your current code needs a couple of changes: $qry = "SELECT userID, username FROM users WHERE lastvisit > '$tm' and online='ON'" $qt=mysql_query($qry) or die("An Error Occured trying to run the following:<br>$qry<br><br>The Server Responded With:<br>".mysql_error()); while($nt=mysql_fetch_array($qt)){ echo "<tr><td><a href=\"profile.php?uid={$nt['userID']}\"> {$nt['username']} </a></td></tr>"; } ?> then on the profile.php have the following code: <?php if(isset($_GET['uid'])){ $id = $_GET['uid']; $sql = "SELECT all, profile, info, fileds FROM profileTable WHERE userID = "id"; $result = mysql_query($sql) or die ("An Error Occured trying to run the following:<br>$qry<br><br>The Server Responded With:<br>".mysql_error()); while($row = mysql_fetch_assoc($result){ //display fields } } ?> That's obviously the bare minimum, and you will need to adapt it to your SQL info, but hopefully it's something that you can work with. Please look over the revision I made to your original code and note the changes, perticulaty the use of single quotes within [], and the use of {} around array key reffrences inside of strings. Link to comment https://forums.phpfreaks.com/topic/259399-turning-each-array-value-into-a-link/#findComment-1329752 Share on other sites More sharing options...
Zhyrios Posted March 22, 2012 Author Share Posted March 22, 2012 Thank you guys, you's made me realise i finally needed an id field in my database. this did the trick, thanks ^^ Link to comment https://forums.phpfreaks.com/topic/259399-turning-each-array-value-into-a-link/#findComment-1330074 Share on other sites More sharing options...
Muddy_Funster Posted March 22, 2012 Share Posted March 22, 2012 Thank you guys, you's made me realise i finally needed an id field in my database... Link to comment https://forums.phpfreaks.com/topic/259399-turning-each-array-value-into-a-link/#findComment-1330123 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.