SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Finland
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using links to show info from MySQL DB

    I want to use country's name as link.
    In first page(index.php) there is a link, country's name(in this case finland or sweden).When I click on link, it opens second page(country_info.php) which shows the information about country. All information is in DB called test, table called country.

    mysql> select * from country;
    +---------+----------+------------+
    | name | capital | population |
    +---------+----------+------------+
    | finland | helsinki | 5000000 |
    | sweden | stocholm | 10000000 |
    +---------+----------+------------+

    I can't make the link work properly! I made country's name as link and it opens new page, but it wont show the information about country. Second page should look like this:

    FINLAND
    Capital: Helsinki
    Population: 5000000

    This is simplified example, my DB is much larger and this kind of linksystem would be handy.

    Thanks in advance!

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    if (!isset($_GET['country']) or empty($_GET['country']) {
        die(
    'No country selected. Please go <a href="index.php">back</a> and try again.');
    } else {
        
    $cx mysql_connect('localhost''root''') or die(mysql_error());
        
    mysql_select_db('test');
        
    $country get_magic_quotes_gpc() ? $_GET['country'] : mysql_escape_string($_GET['country']);
        
    $sql "SELECT capital, population 
                FROM country 
                WHERE name = '
    $country'";
        
    $res mysql_query($sql) or die(mysql_error());
        
    $num mysql_num_rows($res);
        if (
    $num == 0) {
            die(
    'Unknown country. Please go <a href="index.php">back</a> and try again.');
        } else {
            
    extract(mysql_fetch_assoc($res);
            echo 
    '<h3>'.$_GET['country'].'</h3>';
            echo 
    '<p>Capital: '.$capital.'<br />';
            echo 
    'Population: '.$population.'</p>';
        }


  3. #3
    SitePoint Addict Resident Evil's Avatar
    Join Date
    May 2003
    Location
    Barrow
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry never read the first lines of post


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
  •