Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2004, 07:45 PM
Mephisteus's Avatar
Mephisteus Mephisteus is offline
 
Join Date: Dec 2001
Location: The Netherlands
Posts: 288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Howto get info from a mysql query? Resource ID #23 is all I get

I have this query: $activeusers = $DB_site->query("
SELECT user.*, usergroup.*
FROM " . TABLE_PREFIX . "user AS user
LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup ON(usergroup.usergroupid=user.usergroupid)
WHERE user.tsserver_timestamp != ''
ORDER BY usergroup.orderid DESC, user.username ASC
");

This returns "Resource id #23". Now this may sound stupid, but how do I get info from that?

PS
If it's in the wrong part, sorry, was kind of unsure where to put it since I got the query, just not the php :P
Reply With Quote
  #2  
Old 09-28-2004, 08:49 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The forum is correct, that's not a forum for php allone, but for mysql html or js help as well.

As for your actual bug: what is returning Resource id23?

the $DB_site->query() function returns a mysql result set (speak a resource) so are you trying to work on that resource itself without using a fetch_array?
Reply With Quote
  #3  
Old 09-29-2004, 10:44 AM
Mephisteus's Avatar
Mephisteus Mephisteus is offline
 
Join Date: Dec 2001
Location: The Netherlands
Posts: 288
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am not sure how to use fetch_array I took a look at the php.net manual but all the output I got was only one name instead of the two (that were on and met requirements) at the time.
Reply With Quote
  #4  
Old 09-29-2004, 11:19 AM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

fetch_array is used to take the results from a query and turns them into arrays, making them easy to work with in php.

Lets take this for example:

I want to get the 5 newest usernames from my database, but I want to put a bit of text on a new line under the last username returned from mySQL.

So I write this line to query the data:

PHP Code:
$getusers $DB_site->query("SELECT username FROM user ORDER BY userid DESC LIMIT 5"); 
That gets the 5 rows I need from mySQL, but how do I use them in the templates or in the rest of my page for that matter? Obviously $getusers dose nothing.

This is where fetch_array comes in.

As stated before I want to add text under the last username mySQL returned, which means I need to loop over the results (look at them one at a time). For the loop operation I will use the while function, you will notice fetch_array is called within this function, this is the most common useage of $DB_site->fetch_array(); within vBulletin.

So heres you basic code for the loop/fetch_array operation

PHP Code:
$looped_x_times 0// this var will tell us how many times the while loop has run
while ($users $DB_site->fetch_array($getusers))
{
    
// if we have already looped 4 times then this is the 5th run
    
if ($looped_x_times == '4')
    {
        
// append <br /> and 'Last result' to the username this run
        
$users['username'] = ''.$user['username'].'<br />Last result';
    }

    
// Outputs username of the member we are currently looking at in the loop
    
echo($users['username']);
    
    
/* 
    This will add 1 (+1) to the $looped_x_times var, so if looped_x_times is '0' this will set it to '1', and so on
    */
    
$loop_x_times++; 
$DB_site->fetch_array is mysql_fetch_array(); in php, you can find out more info on mysql_fetch_array(); here: http://www.php.net/mysql_fetch_array
Reply With Quote
  #5  
Old 10-28-2008, 08:24 AM
jfk1 jfk1 is offline
 
Join Date: Mar 2008
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

would it be possible to re-open this thread? i appreciate it is very old...
Reply With Quote
  #6  
Old 10-28-2008, 12:22 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well you just did.....

But information in this thread does not apply to later vBulletin versions. Please open a new thread or look in our Articles section.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:02 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04018 seconds
  • Memory Usage 2,216KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete