SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist jazztie's Avatar
    Join Date
    Mar 2001
    Location
    the Netherlands
    Posts
    519
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is probably very easy, but somehow I'm quite hard-headed and still don't understand fully how to do the following...

    I have a table:
    links (userid, linkid, name, URL)
    userid foreign key user.id

    So, one user can have 0, 1 or many links.

    I want to print the links a user has.
    How can I do this so it will look like this:


    Link 1
    Link 2
    Link 3
    Link 4
    Link 5

  2. #2
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ok...

    well, I haven't used mysql's db functions much since I abstracted them to my own - much simpler library which I use all the time - so please pardon any slight mistakes

    anyhow, you should be able to do something like:
    Code:
    $result = mysql_query("select link, URL from links where userid = $userid");
    if($result) {
      if(mysql_num_rows($result) > 0) {
         while(list($linkname, $linkurl) = mysql_fetch_row($result)) {
            echo "<a href=\"$linkurl\">$linkname</a><br>";
         }
       }
    } else { echo "no links"; }
    please note that you will need a variable called "$userid" which holds the user's-in-question userid for this to work!

    see if that doesn't work for you
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or to simplify it a bit

    PHP Code:
    <?
    $result 
    mysql_query("select link, URL from links where userid = $userid");
    if(
    mysql_num_rows($result) > 0) {
        while(
    $row mysql_fetch_array($result)) {
            
    extract($row);
            print 
    "<a href=\"$URL\">$link</a><br>";
            }
        } 
    else { 
        echo 
    "no links"
        }
    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Zealot Alarion's Avatar
    Join Date
    May 2001
    Location
    Virginia
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oO Freddy... I didn't know you could do it that way (talking about the "extract" and then reference the column name as a variable.
    thanks
    -=Alarion=-
    Protollix - Linux hosting from $3.95/m


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
  •