Page 1 of 1

general php link mysql select values

Posted: Tue Dec 11, 2007 7:40 pm
by DonPatricio91
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi,

i programmed a simple register and login script. I am now working on a member script, showing all members who have registered. I got that. I did following:

Code: Select all

$user_registered = mysql_query ("SELECT * from users;") or die ("error");

while ($user_registered_value = mysql_fetch_object($user_registered))
{

echo "<A HREF='mysite.php?id=$user_registered_value->id'>
$user_registered_value->username</A><BR>";
}
that works perfectly, searches through my database and displays every user. however, when I click on the link of one of the displayed members, I want to display the profile information of the selected user on the linked page. So, i want to display the username or first name and etc. of the selected user (the values are in the database).

Does anybody know what I am supposed to do so I can display the profile information? All I actually need to know to code this is either the ID or username of the selected user. Then I would be able to make another simple select query like: select * from users where id/username = '$id/$username' But I don't know these values. i see that something i beeing sent through the link, but how do proceed? so, i have no clue. I would really appreciate it if somebody could help me. thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Dec 11, 2007 9:12 pm
by farkewie
You need to have aces to the mysql db (phpmyadmin),

it looks like the id ( primary key) is being sent through the links.


so you need to get that and make your query

something like this

Code: Select all

<?php

if ( isset($_GET['id']) )
{

    $user_info = "SELECT * FROM users WHERE id='" . $_GET['id'] . "' LIMIT 1";

    if ( !$user_info_query = mysql_query($user_info) )
    {
        echo "Could not query the database.<br>Database error: <b>" . mysql_error();
        die;
    }
    if ( !$user_details = mysql_fetch_assoc($user_info_query) )
    {
        echo "Could not get user details<br>Database error: <b>" . mysql_error();
        die;
    } else
    {
        echo $user_details['first_name'] . "<br />";
        echo $user_details['last_name'] . "<br />";
        echo $user_details['username'] . "<br />";
    }
}
?>
if you are selecting from a different table you will need to make sure you are using a common field between the 2 tables like username or something.
you will also need to change the echo values to suit what is in your tables eg: first_name might be fname

Posted: Tue Dec 11, 2007 10:48 pm
by DonPatricio91
Thank You so much, I really appreciate you helping me out. Thanks a lot, works perfectly.

Posted: Tue Dec 11, 2007 11:11 pm
by farkewie
DonPatricio91 wrote:Thank You so much, I really appreciate you helping me out. Thanks a lot, works perfectly.
More than happy to help. Anymore questions feelfree to post.