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 05-31-2007, 12:13 PM
The)TideHunter( The)TideHunter( is offline
 
Join Date: May 2007
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default SQL problems

Hey, i've never really used sql before, i've tried but to no avail.
What im asking for is a query that will add a new section to the table (preferablly called "coins") and 2 functions which are Get and Set for the coins.

So for example, every member has a coins section (just like posts) and 2 functions like:

function Get takes userid returns coinsamount

function Set takes userid, coinsamount.

I'm really having trouble doing this, any help appreiciated.
Reply With Quote
  #2  
Old 05-31-2007, 10:21 PM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by The)TideHunter( View Post
Hey, i've never really used sql before, i've tried but to no avail.
What im asking for is a query that will add a new section to the table (preferablly called "coins") and 2 functions which are Get and Set for the coins.

So for example, every member has a coins section (just like posts) and 2 functions like:

function Get takes userid returns coinsamount

function Set takes userid, coinsamount.

I'm really having trouble doing this, any help appreiciated.
You need to add the coins field to the table

[sql]alter table tablename add column coins int(11);[/sql]

getter
[sql]select coins from tablename where userid=something[/sql]

setter
[sql]update tablename set coins=something where userid=somethingelse[/sql]
Reply With Quote
  #3  
Old 06-02-2007, 07:18 AM
The)TideHunter( The)TideHunter( is offline
 
Join Date: May 2007
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks so much, exactly what i needed.

EDIT: I'm having problems, i tried this code:

PHP Code:
<?php

    
require_once('./global.php');
    require_once(
DIR '/includes/functions_bigthree.php');
    require_once(
DIR '/includes/functions_forumlist.php');
    
// sql coins test
    
$db->query_read_slave("update user set coins=5 where userid=1");
    
    
$coins $db->query_read_slave("select coins from user where userid=1");
    
    echo 
$coins;
?>
And i added the column coins successfully to table users.
Whenever i try the page it returns "Resource id #16".
Reply With Quote
  #4  
Old 06-03-2007, 10:56 PM
Eikinskjaldi's Avatar
Eikinskjaldi Eikinskjaldi is offline
 
Join Date: Feb 2006
Location: Hell, never looked better
Posts: 572
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

query_read_slave sets the database object with a cursor, it does not return the actual values.


also when not doing a select you should use query_write. (I think...dont quote me on this one)


PHP Code:
    // sql coins test
    
$db->query_write("update user set coins=5 where userid=1");
    
    
$coins_query $db->query_read_slave("select coins from user where userid=1");
    
    while (
$coins $db->fetch_array($coins_query))
            echo 
$coins['coins']; 
Reply With Quote
  #5  
Old 06-04-2007, 12:08 PM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Eikinskjaldi View Post
also when not doing a select you should use query_write. (I think...dont quote me on this one)
Partly correct, use query_write when WRITING to the database and query_read when READING. Pretty logical actually.
Reply With Quote
  #6  
Old 06-04-2007, 03:55 PM
The)TideHunter( The)TideHunter( is offline
 
Join Date: May 2007
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks alot guys, its working now.
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 10:52 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.05582 seconds
  • Memory Usage 2,215KB
  • 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
  • (2)bbcode_quote
  • (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_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