SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member white_spider77's Avatar
    Join Date
    Feb 2003
    Location
    wales
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help I'm new and stuck with php and mysql

    Hi Guys, I've set up two tables in mySql (example nametbl and addtbl).

    I have a frontpage.php which lists all the details of the nametbl as <a href>links which I want to load into a new page with all details when a user clicks the link.

    The problem I have is want to load only that link (i.e

    nametbl

    Scott
    Jane
    Bob

    if user clicks on 'scott' then I want to load a new page with different formats with :

    nametbl addtbl

    Scott my address details

    I getting trouble finding out to get the php to take the id of the name and pass it to the new page then load that specific id row only.

    can anyone help me.!!!!!! PLEASE!!!!!!

    white_spider77

  2. #2
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you send them to another page, say "details.php"

    You just need to add a query string to it, so it would become "details.php?userid=<?=$userid?>" when you print the link to the details.php page...

    Inside the details.php page, use "$userid = $_GET['userid'];" and in your mySQL query add "WHERE userid=$userid"

    If you're still having problems post your code

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Just to give you some code to start with (that coincide with what platinum posted).
    PHP Code:
    // PAGE 1
    // LISTING ALL THE NAMES
    $conn mysql_connect('server''user''password') or die(mysql_error);
    $db mysql_select_db('databasename'$conn);
    $sql "SELECT nameid, name FROM nametbl";
    $result mysql_query($sql$db) or die(mysql_error());
    while(
    $row mysql_fetch_array($result)) {
        
    $nameid $row['nameid'];
        
    $name $row['name'];
        echo 
    "<a href=""\"details.php?nameid=$nameid\">$name</a><br>\n";
    }

    // PAGE 2
    // LISTING ALL INFO ABOUT THE SELECTED NAME
    $conn mysql_connect('server''user''password') or die(mysql_error);
    $db mysql_select_db('databasename'$conn);
    $sql "SELECT id, address, email FROM addtbl WHERE id=" $_GET['nameid'];
    $result mysql_query($sql$db) or die(mysql_error());
    $row mysql_fetch_array($result)
    echo 
    'id: ' $row['id'] . "<br>\n";
    echo 
    'Address: ' $row['Address'] . "<br>\n";
    echo 
    'Email: ' $row['Email'] . "<br>\n"
    If you want more help on the queries you need to provide more information on what fields you have in the db table.

    Hope this gives you a start.

    -Helge

  4. #4
    SitePoint Member white_spider77's Avatar
    Join Date
    Feb 2003
    Location
    wales
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers guys.
    I'll let you know on the results.

    white_spider77


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
  •