View Full Version : Display database information
051119
01-03-2010, 03:18 PM
I have the SQL query SELECT vb_user.username, vb_userfield.field14 FROM vb_userfield
JOIN vb_user ON vb_user.userid = vb_userfield.userid
ORDER BY vb_userfield.field14 DESCCan anyone advise how I can get the output of this to appear on a vB powered page?
Lynne
01-03-2010, 03:26 PM
Try looking in any vbulletin php file. This sort of thing is done all the time. Just take a look at the index.php file and how forumusers are defined, or the search.php file and how threads or posts are defined.
051119
01-03-2010, 04:21 PM
Thanks for the reply.
I've added $mileage2010 = $db->query_read_slave("SELECT vb_user.username, vb_userfield.field14 FROM vb_userfield
JOIN vb_user ON vb_user.userid = vb_userfield.userid
ORDER BY vb_userfield.field14 desc"); and also put $mileage2010 onto my page, but nothing is showing!
Lynne
01-03-2010, 07:29 PM
All you've done there is get the pointer. You then need to actually access the data like so:
while ($mileage = $db->fetch_array($mileage2010))
{
$username = $milieage['username'];
// and then spit it out in a template each time you go through the loop
}
Mythotical
01-06-2010, 10:21 PM
Also change that from $db->query_read_slave to $db->query_read, you only use query_read_slave when you have more than 1 query running together.
051119
02-21-2010, 09:14 PM
I'm really sorry, I've been working on this for a while now and really confused by what you mean when you say ''All you've done there is get the pointer. You then need to actually access the data like so''
Lynne
02-21-2010, 09:21 PM
I showed you an example. Doing a select just finds the data (gets a pointer to it), then you need to actually fetch it for use with the fetch_array statement. vB does have a shortcut if you are only fetching one line, and that is instead of saying query_read (or query_read_slave), to just say query_first. If you use that, then you do not have to fetch the data afterwards. It would be available in the array you assigned it to - so $mileage2010['username']
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.