Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to display mysql results as hyperlinks with php

    how do i get the mysql results to display as veiw.php?id=#
    this is my code so far

    PHP Code:



    $link 
    mysql_connect('host''username''pass')
       or die(
    'Could not connect: ' mysql_error());
    echo 
    'Connected successfully';
    mysql_select_db('dbname') or die('Could not select database');


    $query 'SELECT * FROM data';
    $result mysql_query($query) or die('Query failed: ' mysql_error());

    echo 
    "<table>\n";
    while (
    $line mysql_fetch_array($resultMYSQL_ASSOC)) {
       echo 
    "\t<tr>\n";
       foreach (
    $line as $col_value) {
           echo 
    "\t\t<td>$col_value</td>\n";
       }
       echo 
    "\t</tr>\n";
    }
    echo 
    "</table>\n";


    mysql_free_result($result);


    mysql_close($link); 
    any help?

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    what?

    -using 'SELECT *' isn't particularly helpful to others looking at your code
    -you're iterating over all of the columns, where does the link come in to this?

  • #3
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    my question was were would i put the code to select the link from the table

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Are you storing URLs in your database and wanting them to be displayed as hyperlinks or are you wanting to create hyperlinks that can then query your database?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    which link?
    what table?

    is there a link in 'data'? (not the best name for a table...)
    if so, then it will be one of your columns, so something like

    PHP Code:
    foreach ($line as $col_name=>$col_value) { 
      if(
    $col_name=='link')
        echo 
    '<td><a href="'.$col_value.'">Click Here</a></td>';
      else
        echo 
    "\t\t<td>$col_value</td>\n"

  • #6
    Regular Coder googleit's Avatar
    Join Date
    Jul 2006
    Location
    birmingham, uk
    Posts
    189
    Thanks
    0
    Thanked 0 Times in 0 Posts
    storing hyperlinks in db


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •