Is it possible to make a field into a link?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • w33nie
    New Member
    • Jan 2007
    • 56

    Is it possible to make a field into a link?

    I want to get my database working in a way that when the user is viewing my web site, clicking a certain field on my php/mySQL data, will take them to another web page.

    Is this possible?


    and please excuse my probably poor choice of mySQL related words.
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Yes. But are you asking a database question, a php or HTML question? If its all three then we need your DB table structure and the code developed so far

    Comment

    • w33nie
      New Member
      • Jan 2007
      • 56

      #3
      well i have no idea what area i'd be asking it in, but i assumed there might be a way to make a link directly from the mySQL database.
      here's my stuff anyway:

      [PHP]<? $hostname = "p*smysql*.secu reserver.net"; // The mySQL DB server.
      $username = "******"; // The username you created for this database.
      $password = "******"; // The password you created for the username.
      $usertable = "round1"; // The name of the table you made.
      $dbName = "acssl_fixtures "; // This is the name of the database you made.

      MYSQL_CONNECT($ hostname, $username, $password) OR DIE("DB connection unavailable");
      @mysql_select_d b( "$dbName") or die( "Unable to select database");
      ?>
      <?
      //error message (not found message)begins
      $XX = "Table error. Refresh this page or contact the site administrator." ;
      //query details table begins
      $query = mysql_query("SE LECT * FROM `round1` LIMIT 0, 30 ");
      while ($row = @mysql_fetch_ar ray($query))
      {
      $variable1=$row["#"];
      $variable2=$row["home"];
      $variable3=$row["score"];
      $variable4=$row["away"];
      $variable5=$row["time"];
      $variable6=$row["date"];
      //table layout for results

      print ("<tr>");
      print ("<td width='180'><sp an class='Body'>$v ariable2</span></td>");
      print ("<td width='90' align='center'> <span class='Body'>$v ariable3</span></td>");
      print ("<td width='180'><sp an class='Body'>$v ariable4</span></td>");
      print ("<td width='100'><sp an class='Body'>$v ariable5</span></td>");
      print ("<td><span class='Body'>$v ariable6</span></td>");
      print ("</tr>");
      }
      //below this is the function for no record!!
      if (!$variable1)
      {
      print ("$XX");
      }
      //end
      ?>[/PHP]
      this is a database that keeps the records and times of matches.
      I want to convert the variable3, into a link.
      but only have the link working in certain cases.

      Comment

      • w33nie
        New Member
        • Jan 2007
        • 56

        #4
        as in, in some cases, variable3 will be "v", but in other cases it will be a range of numbers.

        i then want to specify a web page, that the user would be taken to upon clicking one of the variable3's.
        but i want it to go to a different web page for different lines of variable3.

        Comment

        • code green
          Recognized Expert Top Contributor
          • Mar 2007
          • 1726

          #5
          Just a tip first. Use single quotes ' ' instead of double " ". They parse much faster.
          but i want it to go to a different web page for different lines of variable3
          Ideally your DB needs another field with the link page. The data could be written into this field in HTML format as a hyperlink or just the filename (recommended). Then when you read the data from the recordset there will be an extra variable [PHP]$link=$row['link']; # contains the linking page filename[/PHP]If 'link' is the filename rather than HTML create the hyperlink at this point.
          [PHP]$link = '<a href="'.$row["link"]. ' "> '.$row['score']. '</a>';[/PHP]maybe what you are looking for. I have spaced out the quotes and periods for clarity but remove the spaces in your code

          Comment

          • w33nie
            New Member
            • Jan 2007
            • 56

            #6
            Originally posted by code green
            Just a tip first. Use single quotes ' ' instead of double " ". They parse much faster.Ideally your DB needs another field with the link page. The data could be written into this field in HTML format as a hyperlink or just the filename (recommended). Then when you read the data from the recordset there will be an extra variable [PHP]$link=$row['link']; # contains the linking page filename[/PHP]If 'link' is the filename rather than HTML create the hyperlink at this point.
            [PHP]$link = '<a href="'.$row["link"]. ' "> '.$row['score']. '</a>';[/PHP]maybe what you are looking for. I have spaced out the quotes and periods for clarity but remove the spaces in your code
            thanks, that works just fine.
            but, i can't get rid of the underline under my fields when i view the web site now.
            I've got the proper css file set up, everything in it works except for the underline.
            any suggestions?

            Comment

            • code green
              Recognized Expert Top Contributor
              • Mar 2007
              • 1726

              #7
              [HTML]text-decoration:none[/HTML]

              Comment

              Working...