View Full Version : Help with mysql select and array
Kirk Y
05-13-2006, 01:48 AM
Okay, so what I'm trying to do here is have a table underneath the member.php (memberinfo template) page with game statistics that are stored in a db. I've got a profile field set up where the users put in their username for the game -- that's how their stats are pulled from the table. So, table configuration: I've got around 9 or 10 fields, with things like kills, deaths, headshots, etc. What I'm trying to do is run a select query like: "SELECT * FROM table_name WHERE name = '$post[field5]'" And from this, I want to generate an array so I can use $stat[kills] or w/e in a template to post the row data from the kills field. Does that make sense? Anyway -- thanks in advance for any help. It's much appreciated.
I've tried a bunch of codes that people have posted with similar problems -- but none of them yield any results.
Chroder
05-13-2006, 05:33 PM
So the table has columns for kills, deaths etc? So all you need is a single row.
Something like this?
$game_uname = $vbulletin->db->sql_prepare($userinfo['field5']);
$stats = $vbulletin->db->query_first("SELECT * FROM tablename WHERE name = $game_uname LIMIT 1");
Kirk Y
05-13-2006, 06:16 PM
I tried using the code you supplied, but nothing shows up when I use the $stats var in a template. But yes, that's how my table is set up.
Chroder
05-13-2006, 06:26 PM
Which hook are you using?
Kirk Y
05-13-2006, 08:44 PM
global_complete
Chroder
05-13-2006, 08:54 PM
global_complete is too late, and global ;)
Try using member_complete instead.
Kirk Y
05-13-2006, 09:11 PM
Ah ha! That did it, that'd explain why my other codes weren't working -- he he. Thanks a lot Chroder!
Edit: Oh and Chroder -- do you by chance know how I can connect to a seperate database with this?
Kirk Y
05-15-2006, 07:06 PM
Bump: Connecting to another database?
hambil
05-16-2006, 11:58 AM
Bump: Connecting to another database?
switch (strtolower($vbulletin->config['Database']['dbtype']))
{
// load standard MySQL class
case 'mysql':
case '':
{
$db_temp =& new vB_Database($vbulletin);
break;
}
// load MySQLi class
case 'mysqli':
{
$db_temp =& new vB_Database_MySQLi($vbulletin);
break;
}
}
$db_temp->connect(
$vbulletin->config['Database']['dbname'],
$vbulletin->config['MasterServer']['servername'],
$vbulletin->config['MasterServer']['port'],
$vbulletin->config['MasterServer']['username'],
$vbulletin->config['MasterServer']['password'],
true
);
Kirk Y
05-16-2006, 07:32 PM
What should I change my select code to?
$stats = $vbulletin->db->query_first("SELECT * FROM stats_new WHERE name = $game_uname");
Edit: Nevermind, I'm such an idiot -- lol. Thanks for the assist hambil.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.