vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   MySQL Not grabbing everything for my hack? (https://vborg.vbsupport.ru/showthread.php?t=67884)

Ryan Ashbrook 08-01-2004 10:54 PM

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.

Andreas 08-01-2004 11:00 PM

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];


]

Ryan Ashbrook 08-01-2004 11:04 PM

I know it doesn't support prefixes, as it's custom to my forums and we don't have a prefix. ;)

Brad 08-01-2004 11:42 PM

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']; 


Ryan Ashbrook 08-01-2004 11:52 PM

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.

Andreas 08-02-2004 12:34 AM

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 />";



Ryan Ashbrook 08-02-2004 07:15 PM

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.

Colin F 08-02-2004 07:18 PM

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

with a .=

if you forget the . it just overwrites the variable.

Ryan Ashbrook 08-02-2004 07:26 PM

... 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. :p

Colin F 08-02-2004 07:42 PM

no problem...

oh and... write it down for next time ;)


All times are GMT. The time now is 05:12 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.01186 seconds
  • Memory Usage 1,769KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete