PDA

View Full Version : Troublesome SQL queries


RaidenDAWG2
08-08-2005, 10:36 AM
I'm working on a major game development project (fully vB integrated) for my site, and I'm having a problem getting a couple of functions to work.

The first one here fetches the info for a given team. I did some testing (echoed variables), and I found that while the $userid variable was set properly, the query following it wasn't functioning as designed (i.e. it returns nothing).


function fetch_teaminfo($userid, &$teaminfo)
{
global $vbulletin;
//requires that is an actual owner.
$userid = intval($userid);
$teaminfo = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."fwteams WHERE ownerid = $userid");
}

Second one works on determining if the user is a team owner or GM (haven't implemented the second half yet, so it by default returns 0 for false).


function check_status($userid, $docheckon)
{
global $vbulletin;
$userid = intval($userid);
if($docheckon == 'owner')
{
$yayornay = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."fwowners WHERE ownerid = $userid");
if($yayornay == '1')
{
return 1;
}
else
{
return 0;
}
}
if($docheckon == 'gm')
{
return 0;
}
}

Again, did some testing on this, the $userid is set, but for some reason the query's not functioning.

Sorry if these are stupid questions guys. Haven't exactly had any formal training in MySQL or PHP, been basically learning on my own for the last two months or so (have experience with Java and RESOLVE/C++) through trial and error.

Thanks for any help :)

EDIT: Should mention, all of the above is programmed for 3.5 RC1

-RD

Logikos
08-08-2005, 10:45 AM
I think it has to do with

$vbulletin->db->query_read();


Have you tried:

$vbulletin->db->query();

Marco van Herwaarden
08-08-2005, 11:46 AM
If you have only row that fullfills the WHERE clause, you should use query_first instead of query_read (and not 'query' like LV suggested :P 'query' is depreciated and should be replaced by either query_read or query_write).

The 'read' in query_read only means that this query will not change any data (query_write), it is not fetching the results.

If you have more rows that will be returned, use the following construct:
$result= $vbulletin->db->query_read("SELECT * FROM table WHERE condition");
while ($row= $vbulletin->db->fetch_array($result))
{
...process row
}

RaidenDAWG2
08-08-2005, 12:20 PM
I feel stupid now. Thanks Marco, really appreciate it man :D

-RD