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 08-01-2004, 10:54 PM
Ryan Ashbrook's Avatar
Ryan Ashbrook Ryan Ashbrook is offline
 
Join Date: Dec 2002
Location: Cincinnati, Ohio
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default MySQL Not grabbing everything for my hack?

This is why I hate working with MySQL.

I'm translating a hack from wBB 1.2 to vB 3.0.3 so that I can use it on my forums.

Problem is, I think I'm using the right code, but the SQL query is only grabbing one of the objects in the table, and not all of them.

PHP Code:
$thread_sword $DB_site->query_first("SELECT sword FROM user WHERE userid='$bbuserinfo[userid]'");
$result $DB_site->query("SELECT id, swordname, money FROM swords ORDER BY id ASC");
while (
$item $DB_site->fetch_array($result))
{
    
$sword $item[swordname];
    
$money $item[money];
    
$id $item[id];

That is the code I'm using, and when I try to get the 44 objects from the table it only shows the one with an ID of 44, instead of all of the objects.
Reply With Quote
  #2  
Old 08-01-2004, 11:00 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, this code is moreless the same as:

PHP Code:
$thread_sword $DB_site->query_first("SELECT sword FROM user WHERE userid='$bbuserinfo[userid]'");
$result $DB_site->query("SELECT id, swordname, money FROM swords ORDER BY id ASC");
while (
$item $DB_site->fetch_array($result))
{
  
// Do nothing




Furthermore, your code does not support table prefixes:
PHP Code:
 $thread_sword $DB_site->query_first("SELECT sword FROM " TABLE_PREFIX "user WHERE userid='$bbuserinfo[userid]'");
$result $DB_site->query("SELECT id, swordname, money FROM " TABLE_PREFIX "swords ORDER BY id ASC");
while (
$item $DB_site->fetch_array($result))
{
    
$sword $item[swordname];
    
$money $item[money];
    
$id $item[id];

]
Reply With Quote
  #3  
Old 08-01-2004, 11:04 PM
Ryan Ashbrook's Avatar
Ryan Ashbrook Ryan Ashbrook is offline
 
Join Date: Dec 2002
Location: Cincinnati, Ohio
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I know it doesn't support prefixes, as it's custom to my forums and we don't have a prefix.
Reply With Quote
  #4  
Old 08-01-2004, 11:42 PM
Brad Brad is offline
 
Join Date: Nov 2001
Posts: 4,765
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

First off why are you running this query?

PHP Code:
 $thread_sword $DB_site->query_first("SELECT sword FROM " TABLE_PREFIX "user WHERE userid='$bbuserinfo[userid]'"); 
This will work just as well and avoids the query:

PHP Code:
$thread_sword $bbuserinfo['sword']; 
Reply With Quote
  #5  
Old 08-01-2004, 11:52 PM
Ryan Ashbrook's Avatar
Ryan Ashbrook Ryan Ashbrook is offline
 
Join Date: Dec 2002
Location: Cincinnati, Ohio
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Brad, I've changed things around now to this.

PHP Code:
    // What Sword User has Now
     
$thread_sword $bbuserinfo['sword'];
    
// All Items
    
$item_results $DB_site->query_first("
        SELECT id, swordname, money FROM swords
        ORDER BY id DESC
    "
);
    while (
$item $DB_site->fetch_array($item_results))
    
$item['swordname'] = $item_results[swordname];
    
$item['money'] = intval ($item_results[money]);
    
$item['id'] = intval ($item_results[id]);
    } 
And now only the cost of the last item shows up. Nothing else.
Reply With Quote
  #6  
Old 08-02-2004, 12:34 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
$item_results $DB_site->query_first("
        SELECT id, swordname, money FROM swords
        ORDER BY id DESC
    "
);
    while (
$item $DB_site->fetch_array($item_results))
    
$item['swordname'] = $item_results[swordname];
    
$item['money'] = intval ($item_results[money]);
    
$item['id'] = intval ($item_results[id]);
    } 
What the hell are you doing here?
$item_results is an associative array (with keys id, swordname and money). You can't use this as a parameter for fetch_array(), which expects a mySQL result resource (eg. a handle which basically is an integer).

I can only guess that what you want to do is smth. like tis:
PHP Code:
// What Sword User has Now
$thread_sword $bbuserinfo['sword'];
// All Items
$item_results $DB_site->query("SELECT id, swordname, money
                                 FROM " 
TABLE_PREFIX "swords
                                 ORDER BY id DESC
                                "
);
while (
$item $DB_site->fetch_array($item_results)) {
  echo 
"Fetched row is id: $item[id], swordname: $item[swordname], money: $item[money]<br />";

Reply With Quote
  #7  
Old 08-02-2004, 07:15 PM
Ryan Ashbrook's Avatar
Ryan Ashbrook Ryan Ashbrook is offline
 
Join Date: Dec 2002
Location: Cincinnati, Ohio
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes, that is what I want. But it doesn't work when I replace the echo with a template. I still only get one item.
Reply With Quote
  #8  
Old 08-02-2004, 07:18 PM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

be sure to fetch the template like this:
eval('$template .= "' . fetch_template('item') . '";');

with a .=

if you forget the . it just overwrites the variable.
Reply With Quote
  #9  
Old 08-02-2004, 07:26 PM
Ryan Ashbrook's Avatar
Ryan Ashbrook Ryan Ashbrook is offline
 
Join Date: Dec 2002
Location: Cincinnati, Ohio
Posts: 422
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

... a dot...

I cannot believe I spent three whole days working on this and all I needed to add was a dot...

Thanks. I'll go hit my head on something now.

[high]* Ryan Ashbrook bangs head on desk...
[/high]

That's for the help.
Reply With Quote
  #10  
Old 08-02-2004, 07:42 PM
Colin F's Avatar
Colin F Colin F is offline
 
Join Date: Jul 2004
Location: Switzerland
Posts: 1,551
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

no problem...

oh and... write it down for next time
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 11:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04983 seconds
  • Memory Usage 2,288KB
  • Queries Executed 11 (?)
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
  • (8)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete