...

View Full Version : Completely stuck



Nightfire
07-01-2002, 05:50 PM
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.

bcarl314
07-01-2002, 06:11 PM
Can you post some code showing your problem? Are you using php? Perl? ASP?

Nightfire
07-01-2002, 07:06 PM
@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

bcarl314
07-01-2002, 07:17 PM
Try this...



@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.

Nightfire
07-01-2002, 07:28 PM
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:



$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.

Nightfire
07-01-2002, 08:31 PM
I've fixed it after I took some time from the PC.


$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!";}

Jeewhizz
07-02-2002, 01:40 AM
you can also do this :)



$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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum