vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   help with sql query... (https://vborg.vbsupport.ru/showthread.php?t=131100)

Killahbyte 11-08-2006 06:58 PM

help with sql query...
 
Ok we have a team table that holds all our teams and stats. What i am trying to do is have a sql query that will update user table with the stats from team table. But the only thing updating is one column. I need both. Anyone care to help with this problem?

PHP Code:

        global $db;
        
$sql $db->query_first("select * from " TABLE_PREFIX "userteam WHERE userteamid=$teamid AND WHERE title=$teamtitle");
        if (
$sql){
            
$db->query_write("UPDATE " TABLE_PREFIX "user SET teamtitle = '$teamtile' WHERE $teamid=userteamid AND WHERE title=$teamtitle");
        }else{
            
$db->query_write("UPDATE " TABLE_PREFIX "user SET teamtitle = 'NULL' WHERE userteamid=$teamid");                                    
        } 

What is happening is the teamid in user table updates but the teamtitle does not. Where is my error?

KB

Reeve of shinra 11-08-2006 07:58 PM

You dont need to use an if/else... it would be something like


PHP Code:


        $sql 
$db->query_first("select * from " TABLE_PREFIX "userteam WHERE userteamid=$teamid AND WHERE title=$teamtitle");
 
       
$db->query_write("UPDATE " TABLE_PREFIX "user SET teamtitle = '$teamtile' WHERE $teamid=userteamid AND WHERE title=$teamtitle");

       
$db->query_write("UPDATE " TABLE_PREFIX "user SET teamtitle = 'NULL' WHERE userteamid=$teamid"); 

1 - read teh fields in the db
2 & 3 - update those fields

You can probably combine those last two queries into one like in your read query...

r007 11-09-2006 11:39 AM

You also seem to have an error in your 2nd query WHERE clause? (WHERE $teamid=userteamid). Shouldn't it read "WHERE userteamid=$teamid"?


All times are GMT. The time now is 02:19 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.01129 seconds
  • Memory Usage 1,723KB
  • 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
  • (2)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete