I would like a table to return a result set that includes a clickable URL link.

For example

FIRST NAME

JOHN

LAST NAME

RICHARDS

WEBSITE

WWW.RICHARDSSITE.COM

Ideally I would like the link to be in “<A HREF> format so as to rather than show the whole URL, there would just be a link

Eg.

FIRST NAME

JOHN

LAST NAME

RICHARDS

WEBSITE

“CLICK HERE”

Would I be able or recommended to load the “WEBSITE” field of my table with a VARCHAR such as

<A HREF=www.Richardssite.com> CLICK HERE </A>

Or is there a better/correct way to achieve this?

Thank you once again for any help.

    In my scripts for doing this I normally validate the url on input to the db. I always insist on a full url (http://www.domain.com) that way it is easy to extract the url in the database and shove it straight into the HREF -

    <a href="<?=$row['url_field']?>">Click here</a>

    Hope this helps 😉

      Sorry nnichols I was having a bit of trouble seeing how I would fit this into my script (Set out below)

      #!/usr/local/bin/php4

      <html>

      <body>

      <?php

      $link = mysql_pconnect ("", "", "*****")
      or die ("Could not connect");

      mysql_select_db ("****")
      or die ("Could not select database");

      $search = $HTTP_POST_VARS['thebox'];

      $query = "SELECT last_name, link FROM president WHERE last_name LIKE '%$search%'";

      $result = mysql_query ($query)
      or die ("Query failed");

      if ($myrow = mysql_fetch_array($result)) {

      echo "<table border=10>\n";

      echo "<tr><td>Name</td></tr>\n";

      do {

      printf("<tr><td>%s</td></tr>\n", $myrow["last_name"]);
      printf("<tr><td>%s</td></tr>\n", $myrow["link"]);

      } while ($myrow = mysql_fetch_array($result));

      echo "</table>\n";

      } else {

      echo "Sorry, no records were found!";	

      }

      ?>

      </body>

      </html>

      The "link" field obviously is what contains the URL.

      Also, could you just explain what you mean by "validate the url" at the moment it is in the table as http://www.website.

      Thank you yet again for your kind help.

      JD.

        Just change your while loop to something like this -

        do { 
        
        printf("<tr><td>%s</td></tr>\n", $myrow['last_name']);
        
        $pr_link = '<a href="' . $myrow['link'] . '">Click here</a>';
        
        printf("<tr><td>%s</td></tr>\n", $pr_link);
        
        } while ($myrow = mysql_fetch_array($result));

        Hope this helps 😉

          😃 😃

          nnichols - Sir once again I’m in your debt. Worked like a dream!

          When you mention about “Validating” the URL I take it that you mean to just check the address to make sure the link is current?

          Thanks once again for helping me out on this – Sorry to keep “Tugging your coat tails” with what are probably very basic questions!

          JD

            If the urls are being entered by you or an admin validation isn't a big concern, but if they are entered by site users through a form it is always a good idea to do some validation.

            When I validate user entered urls I first check the structure of the input with an ereg() or preg_match(), and then I try to access the url using a socket connection. If both of these succeed I enter the data, otherwise return some form of error.

            Sorry to keep “Tugging your coat tails”

            This is what I love about open source languages like PHP, there is loads of free help available and it helps build this ever growing community of developers. If it weren't for the sharing of ideas and knowledge on here and devshed I would never have got started.

            Hope this helps 😉

              Write a Reply...