SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making a link using PHP coding and HTML

    Hi,

    I have used the select query to get an array of 2 variables. 1 is Name and 2 is a Link.

    If I do this:


    Code:
    while($row = mysql_fetch_array($b))
      {
      echo $row['name'];
      echo $row['link'];
      }
    The output will be wrong just saying
    James www.sitea.com Ben www.siteb.com etc.

    How do I code it in HTML and PHP so that the name James is linked to be clicked to go to sitea and the word Ben is linked to go to siteb.com? They also need to be vertically listed.

    Is this easy?

    Matt.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Just change the echo so it echoes what you want it to echo

  3. #3
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,440
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi Matt,

    Quote Originally Posted by MatthewBOnline View Post
    How do I code it in HTML and PHP so that the name James is linked to be clicked to go to sitea and the word Ben is linked to go to siteb.com? They also need to be vertically listed.
    Looks like what you want is a HTML list, that way they'll be displayed as a vertical list by default. To show the links correctly, they need to be anchor elements, which follow this format:

    HTML Code:
    <a href="www.example.com">My link</a>
    To do this in PHP would look something like this:

    PHP Code:
    echo "<ul>";

    while(
    $row mysql_fetch_array($b))
    {
        echo 
    "<li><a href=\"$row[link]\">$row[name]</a></li>";
    }

    echo 
    "</ul>"
    which will output HTML that looks like this:

    HTML Code:
    <ul>
        <li><a href="www.sitea.com">James</a></li>
        <li><a href="www.siteb.com">Ben</a></li>
    </ul>

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2011
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Fret Burner - that's great. One more thing though...do you know how to make a list spread across the page?

    By this I mean... rather than a continuous long list. The list goes down vertically then it starts again to the right? Like this:


    A I
    B J
    C K
    D L
    E M
    F N
    G
    H

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,440
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    You could use CSS to do that.

    HTML Code:
    <ul class="link_list">
        <li><a href="www.sitea.com">James</a></li>
        <li><a href="www.siteb.com">Ben</a></li>
        <li><a href="www.sitec.com">Freddy</a></li>
        <li><a href="www.sited.com">Brian</a></li>
        <li><a href="www.sitee.com">Rodger</a></li>
        <li><a href="www.sitef.com">John</a></li>
    </ul>
    Code CSS:
    link_list {
      columns: 2;
      -webkit-columns: 2;
      -moz-columns: 2;
    }

    Note that this isn't compatible with older browsers (anything less than IE10, for example). See this compatibility chart for more information.


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
  •