AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   dbi_query : variable help (https://forums.alliedmods.net/showthread.php?t=108206)

MusicSpeed 11-02-2009 18:04

dbi_query : variable help
 
Hi,

I need help on a basic problem (too easy for you maybe ^^).
I don't know how to put variable in SQL Queries by using dbi_query
Here is an example (this is just the problem part i know that i need a dbi_connect ):
Code:
new steamid[35]; get_user_authid(id,steamid,34);   new player_load:res = dbi_query(mysql, "SELECT * FROM mytable WHERE player_steamid = steamid")

I want to know if this code is correct because, if a user connect with a steamid for example STEAM_0:0:123456, the sql query will search for steamid and won't search for STEAM_0:0:123456. (it will search for the variable name and won't search for the variable content)

Thanks a lot and tell if i'm not really understandable

MusicSpeed

unnyquee 11-03-2009 07:41

Re: dbi_query : variable help
 
PHP Code:

new steamid[35]; 
get_user_authid(id,steamid,34); 

new 
szQuery[128];
format(szQuerycharsmax(szQuery), "SELECT * FROM mytable WHERE player_steamid = %s"steamid);

new 
player_load:res dbi_query(mysqlszQuery); 

Hope will that do the trick :)

MusicSpeed 11-03-2009 07:44

Re: dbi_query : variable help
 
Thanks a lot, now i know that i can use %s in a SQL Query ^^
+Karma

I've just another question, do you know how to create my own include file because with pawn studio i created one, added natives and this code at the top
but it didn't recognize it

(myincludefile.inc)
Code:
#if defined _myincludefile_included   #endinput #endif #define _myincludefile_included #include <amxmodx> #include <amxmisc>

MusicSpeed

unnyquee 11-03-2009 07:47

Re: dbi_query : variable help
 
Glad that I could help :)
Good luck in your future works :)
( btw, thx 4 k.. you deserve one too :mrgreen: )

Edit:
Try this:
PHP Code:

#define _myincludefile_included
#if !defined _myincludefile_included
  #endinput
#endif

#include <amxmodx>
#include <amxmisc> 

Second Edit:
PHP Code:

new steamid[35]; 
get_user_authid(id,steamid,34); 

new 
szQuery[128];
format(szQuerycharsmax(szQuery), "SELECT * FROM `mytable` WHERE `player_steamid` = '%s'"steamid);

new 
player_load:res dbi_query(mysqlszQuery); 

Forgot quotes :)

MusicSpeed 11-03-2009 10:56

Re: dbi_query : variable help
 
Thank you for answering me !
All is allright now


All times are GMT -4. The time now is 17:44.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.