SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use php to create hyperlinks

    I want a page to load a list of hyperlinks when the page loads using an SQL statement, then when one link is selected add that value to another SQL statement and produce a second set of links. Is this possible. I do not want to use a drop down list to accomplish this.

    Thanks,

    Dan

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. Post the code you have so far. If you don't have any code, please post in the Looking to Hire forum.

  3. #3
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code and what it gives me is a list of distinct last initials. I would like to convert each to a hyperlink though.

    <?php
    $username = 'physician';
    $password = 'doctor';
    $database = 'jmh';
    $host = 'localhost';

    $connection = mysql_connect ( "localhost", $username, $password );
    if ($connection) {
    echo ("Physician's Directory");
    } else {
    echo ("Error connecting to database!");
    }

    $db_selected = mysql_select_db($database,$connection);
    if (!$db_selected) {
    die('Can\'t use jmh: ' .mysql_error());
    }

    $query = mysql_query("select DISTINCT substr(LastName,1,1) AS Initial from dr_directory");
    ?>

    <!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=iso-8859-1" />
    <title>directory search</title>
    </head>

    <body>
    <?php while($r=mysql_fetch_assoc($query)) {
    echo $r['Initial'] .'<br />';
    }?>
    </body>
    </html>

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to convert each to a hyperlink though.
    Instead of echoing the initials followed by a break tag, echo the initials surrounded by an <a> tag.

  5. #5
    SitePoint Addict hurricanedan's Avatar
    Join Date
    Feb 2006
    Location
    North Carolina
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand that part, but where I am having the problem is I want to know which letter was selected and then run another sql statement using that selection.

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    given a link like this
    Code:
    <a href="foo.php?initial=blah">blah</a>
    foo.php
    PHP Code:
    $initial $_GET['initial']; 


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
  •