SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I add a hyperlink in this php statement?

    I have code similar to this:

    PHP Code:
    $sql "SELECT * FROM authorize AS u_one INNER JOIN authorize AS u_all ON u_all.department IN ( u_one.department , u_one.department2 , u_one.department3 , u_one.department4 , u_one.department5 , u_one.department6 ) WHERE u_one.username = '$_SESSION[user_name]' AND NOT u_all.lockedstatus = 'UNLOCKED'"
    $result mysql_query($sql); 
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    $row['username'];
      echo 
    "<br />";
      } 
    I want to be able to click on the echo $row['username']; and it take me to a page that makes that username a variable on the new page. How do I do this?

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo '<a href="/path/to/script?user="'.$row['username'].'>'.$row['username'].'</a>'
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, how do I get that variable?

  4. #4
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, that line is making one link for all users. I need it to make one link per user listed.

  5. #5
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by wickedneat View Post
    Okay, how do I get that variable?
    On the receiving page you can access it with:

    PHP Code:
    $user $_GET['user']; 

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you put that line in the while loop it should work.
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Immerse View Post
    On the receiving page you can access it with:

    PHP Code:
    $user $_GET['user']; 
    Yes, but don't forget to sanitize/filter your data, first.
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  8. #8
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean the while loop?

    How do I filter my data?

  9. #9
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    the while loop from your sql results.
    PHP Code:
    $sql "SELECT * FROM authorize AS u_one INNER JOIN authorize AS u_all ON u_all.department IN ( u_one.department , u_one.department2 , u_one.department3 , u_one.department4 , u_one.department5 , u_one.department6 ) WHERE u_one.username = '$_SESSION[user_name]' AND NOT u_all.lockedstatus = 'UNLOCKED'"
    $result mysql_query($sql); 
    while(
    $row mysql_fetch_array($result)) 
      { 
     echo 
    '<a href="/path/to/script?user="'.$row['username'].'>'.$row['username'].'</a>';
      echo 
    "<br />"
      } 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #10
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've did that... still making all users the same link.

  11. #11
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    OK looking at the query again it's no surprise that it is bring only 1 result,
    you have a where clause:
    Code:
     WHERE u_one.username = '$_SESSION[user_name]'
    which generally will be one record ie: the one with the user_name matching the session variable.

    What is it that you are trying to do with this?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  12. #12
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That sql statement shows all the users that are in the same departments as the session_username. It shows multible people. But the echo you provided only gives one link, and makes all the usernames that are shown be one whole link.

  13. #13
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Does it display the usernames correctly?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  14. #14
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it does.

  15. #15
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is exactly what I have

    PHP Code:
    mysql_select_db("time"$con);
    $result mysql_query("SELECT * FROM authorize WHERE lockedstatus='UNLOCKED'");
    while(
    $row mysql_fetch_array($result))
      {
    echo 
    '<a href="http://timesheet.com/test/admin/link.php?user="'.$row['username'].'>'.$row['username'].'</a>';   
    echo 
    "<br />"
      }
    mysql_close($con); 

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    well thats me mildy confused then!
    View the source of the page and find the links - are they all the same or different usernames?

    If they are all different then the problem looks to be on the next page and not this one, if they are all the same something is quite wrong!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    ooh actually there is a typo in the link....
    Code:
    echo '<a href="http://timesheet.com/test/admin/link.php?user='.$row['username'].'">'.$row['username'].'</a>';
    " in the wrong place
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #18
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The links are all different, here is a sample link
    Last edited by wickedneat; Aug 8, 2007 at 12:20.

  19. #19
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay that fixed the link problem.

  20. #20
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    yay!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •