Display SQL data in HyperLink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RANJIT SINGH
    New Member
    • Jun 2011
    • 5

    Display SQL data in HyperLink

    I'm very new to PHP and am trying to get one column (called LINK) of data to be displayed in the table, however as a hyper-link. I wish the user to be able to click on the link in order to launch a new quiz for example. Basically I need what is to be displayed by line 81 to be in a hyper-link format.

    Table Display :


    Code:
    <?php require_once('Connections/Education.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
    
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
      return $theValue;
    }
    }
    
    $maxRows_rsMath = 10;
    $pageNum_rsMath = 0;
    if (isset($_GET['pageNum_rsMath'])) {
      $pageNum_rsMath = $_GET['pageNum_rsMath'];
    }
    $startRow_rsMath = $pageNum_rsMath * $maxRows_rsMath;
    
    mysql_select_db($database_Education, $Education);
    $query_rsMath = "SELECT * FROM maths ORDER BY Grade ASC";
    $query_limit_rsMath = sprintf("%s LIMIT %d, %d", $query_rsMath, $startRow_rsMath, $maxRows_rsMath);
    $rsMath = mysql_query($query_limit_rsMath, $Education) or die(mysql_error());
    $row_rsMath = mysql_fetch_assoc($rsMath);
    
    if (isset($_GET['totalRows_rsMath'])) {
      $totalRows_rsMath = $_GET['totalRows_rsMath'];
    } else {
      $all_rsMath = mysql_query($query_rsMath);
      $totalRows_rsMath = mysql_num_rows($all_rsMath);
    }
    $totalPages_rsMath = ceil($totalRows_rsMath/$maxRows_rsMath)-1;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body><?php echo "HELLO WORLD" ?>
    <p>&nbsp;</p>
    <table border="1">
      <tr>
        <td>MathsID</td>
        <td>Grade</td>
        <td>Topic</td>
        <td>Date</td>
        <td>Link</td>
        <td>Image</td>
        <td>Set</td>
        <td>Author</td>
      </tr>
      <?php do { ?>
        <tr>
          <td><?php echo $row_rsMath['MathsID']; ?></td>
          <td><?php echo $row_rsMath['Grade']; ?></td>
          <td><?php echo $row_rsMath['Topic']; ?></td>
          <td><?php echo $row_rsMath['Date']; ?></td>
          <td><?php echo $row_rsMath['Link']; ?> </td>
          <td><?php echo $row_rsMath['Image']; ?></td>
          <td><?php echo $row_rsMath['Set']; ?></td>
          <td><?php echo $row_rsMath['Author']; ?></td>
              </tr>
        <?php } while ($row_rsMath = mysql_fetch_assoc($rsMath)); ?>
    </table>
    </body>
    </html>
    <?php
    mysql_free_result($rsMath);
    ?>
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Hi, Ranjit. Welcome to Bytes.

    Your requirement is simple enough: simply use the $row_rsMath['Link'] data in the HTML anchor element.

    Code:
    echo "<a href='{$row_rsMath['Link']}'>{$row_rsMath['Link']}</a>";
    Hope this helps.

    Comment

    • RANJIT SINGH
      New Member
      • Jun 2011
      • 5

      #3
      Hi Markus,

      Thanks.....The result is in hyper-link, however the contents is not as what is in the database.

      Example, the LINK coloum calls for www.yahoo.com, \Maths\NUMBERS TO 10 000 K3-SET1\quiz.html, etc.

      Result after adding : echo "<a href='{$row_rsM ath['Link']}'>{$row_rsMath['Link']}</a>";

      Comment

      • RANJIT SINGH
        New Member
        • Jun 2011
        • 5

        #4
        Sorry Marcus....it was my mistake. Should have not remove <?php when added your code. It works now with

        Code:
        <td> <?php echo "<a href='{$row_rsMath['Link']}'>{$row_rsMath['Link']}</a>" ?> </td>
        Thank You.....

        Comment

        Working...