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 7 of 7
  1. #1
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts

    Unhappy Completely stuck

    I'm trying to get users details based on what the name of the directory is, I'm using $dir as the variable. I've been trying to do this for ages (about an hour or two) and haven't gotten anywhere.

    I have no idea how to do the select query from the database to choose the right member, based on the directory ($dir).

    The table is named members and I'm wanting to get the username, bio and country from the database. I've tried everyway I can think of, but I get no results or errors.

    I know this might be confusing, thanks if you can help.

  • #2
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Can you post some code showing your problem? Are you using php? Perl? ASP?

  • #3
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    @mysql_connect($dbhost,$dbuname,$dbpass) OR die("Could not connect to the database please make sure the sign in info is correct");
                                        @
    mysql_select_db($dbname) OR die("That database does not appear to exist or you do not have permissions to manipulate it");
                                        
    $sql "SELECT username,country,bio from members";
                                        
    $result mysql_query($sql);

                                        echo 
    "$username    ";
                                        echo 
    "<br>";
                                        echo 
    "$country";
                                        echo 
    "<br>";
                                        echo 
    "$bio"
    I'm new to this so I have no idea on how to do it. Using php

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Try this...

    Code:
    @mysql_connect($dbhost,$dbuname,$dbpass) OR die("Could not connect to the database please make sure the sign in info is correct");
                                        @mysql_select_db($dbname) OR die("That database does not appear to exist or you do not have permissions to manipulate it");
                                        $sql = "SELECT username,country,bio from members";
                                        $result = mysql_query($sql);
                                        $data = mysql_fetch_assoc($result);//new line here.
                                        echo "$data['username']    ";
                                        echo "<br>";
                                        echo "$data['country']";
                                        echo "<br>";
                                        echo "$data['bio']";
    That shoud do it.

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    That throws an error:

    Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\phpdev\www\public\chatterspics\users\nighty\index.php on line 67


    Line 67 is

    echo "$data['username']";

    Also, would this select the right member from the directory name?

    example

    www.chatterspics.com/users/testalias

    testalias is the name of the user I want the details showing of.

    To get the directory name, I'm using:

    PHP Code:
    $url explode("/",$PHP_SELF);
    $filename $url[sizeof($url)-1];
    $dir $url[sizeof($url)-2];

    echo 
    "$dir"
    How can I use that in a select query to get the right users details?

    I tried

    select username,country, bio from members where $dis='username'

    but that never gave a result either.

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I've fixed it after I took some time from the PC.

    PHP Code:
    $result mysql_query("SELECT username,bio, country from members WHERE username='$dir'");
                                        if (
    $row mysql_fetch_array($result)) {

                                        do {
                                          echo 
    $row["username"];
                                          echo 
    "<br>";
                                          echo 
    $row["country"];
                                          echo 
    "<br>";
                                          echo 
    $row["bio"];
                                        } while(
    $row mysql_fetch_array($result));

                                        } else {
                                        echo 
    "Sorry, no records were found!";} 

  • #7
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    369
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can also do this

    PHP Code:
    $result mysql_query("SELECT username,bio, country from members WHERE username='$dir'");
    list(
    $username,$bio,$country) = mysql_fetch_array($result);
    if(
    mysql_num_rows($result)>0)
    {
    echo 
    "$username<br>$country<br>$bio";
    }
    else
    {
    echo 
    "Sorry, no records were found!";

    Jee
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting


  •  

    Posting Permissions

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