Help - Search - Members - Calendar
Full Version: MySQL Help
Invision Power Services > Community Forums > Community Web Design and Coding
Damien Reeves
Hey guys,

Can anyone give me a mysql code to extract a certain users avatar onto the main site?

And I'm not using SSI! I don't even know how to set that up and it's just annoying.

Thanks
Chad
SQL
SELECT avatar,avatar_size FROM ibf_members WHERE id='_MEM_ID_'


Make sure you replace _MEM_ID_ with the variable of the member id somehow.

Chad
Damien Reeves
wouldn't i have to connect to my db first?
Chad
Well yeah, I had assumed you would have already done that.

Without any relevance to what you already have, I can't exactly assume everything you have already completed.

All you asked for was the string to get the Avatar info from the database and that was it.
So thats what I gave you.

If you do not currently know how to connect to MySQL. I suggest reading into that. It will help you in the future for reference.

Chad
Damien Reeves
well ok you didn't have to be so direct jeez ._.
Chad
I am trying to be as helpful as I can be.
I can only do so much with what little information you have given.

In order to receive help, you must give as much information as possible without boring anybody.

All I am trying to do is get you to where you need to be.

Please, don't take my above post so defensive. I am trying to help you.
That is what I am here for. To help you.

My intent above was, to give you information so you know in the future.

As I stated before, I am here to help. original.gif

Chad
Damien Reeves
well it said i connected but

Connected to MySQL
Query failed : No Database Selected

i used this php/mysql code

<?php
$username = "USERNAME";
$password = "PASSWORD";
$hostname = "LOCALHOST";
$dbh = mysql_connect($LOCALHOST, $USERNAME, $PASSWORD)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon
$query = "SELECT avatar,avatar_size FROM ibf_members WHERE id='2'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
mysql_close($dbh);
?>

i'm using invision power board v2
Chad
This is where SQL bugs me sometimes.

You have to select the database after you connect. It would be nice if you could select the database you want within the mysql_connect() function. But you can't.

So here is what needs to done after connecting to MySQL:

CODE
@mysql_select_db("_DATABAS_NAME_",$dbh,);


With _DATABASE_NAME_ beng the actual database name.

Chad
_
QUOTE(Chad @ Mar 13 2005, 11:32 AM)
You have to select the database after you connect.  It would be nice if you could select the database you want within the mysql_connect() function.  But you can't.
*

That's why some people like Perl. :-"

*cough* Sorry for going off topic.
Damien Reeves
erm ok i'm lost >< where exactly in my code do i stick yours?
Michael_C
QUOTE(Chad @ Mar 14 2005, 07:32 AM)
It would be nice if you could select the database you want within the mysql_connect() function.
*

Someone already thought of that. original.gif
Damien Reeves
<?php
$username = "USERNAME";
$password = "PASSWORD";
$hostname = "LOCALHOST";
$dbh = mysql_connect($LOCALHOST, $USERNAME, $PASSWORD)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
@mysql_select_db("ibf_members") or die("Could not select database");
// you're going to do lots more here soon
$query = "SELECT avatar,avatar_size FROM ibf_members WHERE id='2'";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
mysql_close($dbh);
?>

ok i used that and got

Connected to MySQL
Could not select database

when i tried using your code it said: Parse error: parse error, unexpected ')' in /home/jdi/public_html/pages/test.htm on line 18

Can someone just amend my code please?
_
ibf_members is not the database. Find $info['sql_database'] or something like that in conf_global.php.
Damien Reeves
oh crap yeah XD

well now i'm getting this

Parse error: parse error, unexpected ')' in /home/jdi/public_html/pages/test.htm on line 18
KN
BTW, I just noticed something.

CODE
$dbh = mysql_connect($LOCALHOST, $USERNAME, $PASSWORD)
or die("Unable to connect to MySQL");


should probably be

CODE
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
Damien Reeves
Got it biggrin.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.