Log in

View Full Version : noob sql fetch array question


keymistress
11-08-2005, 08:22 AM
i know how to do a normal php mysql fetch array but using vb3's codes, i'm lost!

can somebody guide me please... here's my not-working code:
global $vbulletin;

$query = $vbulletin->db->query_read("SELECT * FROM mob WHERE memberID LIKE '$userId'");

$result = $vbulletin->db->fetch_array($query);
$result['smsCredits'] = $smsCredits;

echo "My Credits: $smsCredits";
$vbulletin->db->free_result($query);

i can't get $smsCredits... :(

Alan @ CIT
11-08-2005, 08:56 AM
$result['smsCredits'] = $smsCredits; is back-to-front. Change it to:
$smsCredits = $result['smsCredits'];

keymistress
11-08-2005, 03:29 PM
i've got it all working now writing it like this

function foo()
{
global $vbulletin;

$query = $vbulletin->db->query_read("SELECT * FROM " . mob . " WHERE memberID LIKE " . $vbulletin->userinfo['userid']);

$result = $vbulletin->db->fetch_array($query);
$smsCredits = $result['smsCredits'];
return $smsCredits;
$vbulletin->db->free_result($query);
}

$smsCredits = foo();


then i show the $smsCredits in my template...
it looks kinda complicated, is there a simplified way of writing this?