Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-01-2002, 04:50 PM   PM User | #1
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 07-01-2002, 05:11 PM   PM User | #2
bcarl314
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
bcarl314 will become famous soon enough
Can you post some code showing your problem? Are you using php? Perl? ASP?
bcarl314 is offline   Reply With Quote
Old 07-01-2002, 06:06 PM   PM User | #3
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 07-01-2002, 06:17 PM   PM User | #4
bcarl314
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
bcarl314 will become famous soon enough
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.
bcarl314 is offline   Reply With Quote
Old 07-01-2002, 06:28 PM   PM User | #5
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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.
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 07-01-2002, 07:31 PM   PM User | #6
Nightfire
Senior Coder

 
Nightfire's Avatar
 
Join Date: Jun 2002
Posts: 4,266
Thanks: 6
Thanked 48 Times in 48 Posts
Nightfire is on a distinguished road
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!";} 
__________________
Blue Panda
Website Design | 1 Pound Ads | 'ow much? | Coding Geeks
Nightfire is offline   Reply With Quote
Old 07-02-2002, 12:40 AM   PM User | #7
Jeewhizz
Regular Coder


 
Join Date: May 2002
Location: London, England
Posts: 369
Thanks: 0
Thanked 0 Times in 0 Posts
Jeewhizz is an unknown quantity at this point
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
Jeewhizz is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:43 AM.


Advertisement
Log in to turn off these ads.