![]() |
[Pawn] Help with mysql and data retrieving. - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3) --- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10) --- Thread: [Pawn] Help with mysql and data retrieving. (/showthread.php?tid=1301) |
Help with mysql and data retrieving. - cronoxliker - 2020-11-02 Hey guys, Im building a gamemode mostly for learning, but i got stuck in faction systems y was following a tutorial but was on an old version and im having struggle getting it done, if someone can explainme what im doing wrong here... Code: stock LoadFactions(/* arguments */) RE: Help with mysql and data retrieving. - Josh - 2020-11-02 If you're getting ALL of the factions just do a SELECT * FROM, there's no need to specify ID. tquery will call a callback (which you specify) where you do cache_ function calls there, the plugin won't know what to do there because you have no cache active. RE: Help with mysql and data retrieving. - cronoxliker - 2020-11-06 Any quick mysql data retrieving guide? im struggling with this, :/ RE: Help with mysql and data retrieving. - DeploYeR - 2020-11-06 // under OnGameModeInit mysql_tquery(mysql_connection// change this to yours, "SELECT * FROM `Factions`", "LoadFactions"); forward LoadFactions(); public LoadFactions() { new rows, fields; cache_get_data( rows, fields, your conn handle ); if( rows ) { for( new i = 0; i < rows; i ) { cache_get_value_int(i,"id",Factions[i][ID]); cache_get_value_name(i,"name",Factions[i][Name]); cache_get_value_name(i,"type",Factions[i][Type]); cache_get_value_name(i,"Rank1",Factions[i][Rank1]); cache_get_value_name(i,"Rank2",Factions[i][Rank2]); cache_get_value_name(i,"Rank3",Factions[i][Rank3]); cache_get_value_name(i,"Rank1",Factions[i][Rank4]); } } return (true); } RE: Help with mysql and data retrieving. - cronoxliker - 2020-11-06 Cache_get_data looks like deprecated i swaped it with cache_get_value_index_int, now, how do i now if it works, i tried with printf but it returns nothing, any idea? thanks for the time guys! my try to print the factions name= CMD:printtest(playerid,params[]) { new query[140]; for(new i = 0; i < MAX_FACTIONS; i) { format(query, sizeof(query),"SELECT * FROM Factions WHERE ID = %d",i); mysql_tquery(g_SQL,query); printf("%s\n", Factions[i][Name]); } return 1; } prints 30 empty rows (yes i know there are rows in the db) thanks! RE: Help with mysql and data retrieving. - Pinch - 2020-11-06 Use cache_get_value_name RE: Help with mysql and data retrieving. - cronoxliker - 2020-11-07 (2020-11-02, 10:11 AM)Josh Wrote: If you're getting ALL of the factions just do a SELECT * FROM, there's no need to specify ID. (2020-11-06, 07:49 PM)Pinch Wrote: Use cache_get_value_name I get -error 035: argument type mismatch (argument 2)- if i just leave the rows as parameter then it will compile but still print 30 blank lines on /printtest, i can upload and edit but i cant retrieve the data... if needed i can pass all the related code. RE: Help with mysql and data retrieving. - Pinch - 2020-11-07 Because cache_get_value_index_int uses column's idx while cache_get_value_name uses literal string. cache_get_value_name(row, "collumn_name", out); Edit: mysql_tquery(g_SQL,query); I don't see a callback there....? Where were you using cache functions at all...? RE: Help with mysql and data retrieving. - cronoxliker - 2020-11-10 (2020-11-07, 11:20 AM)Pinch Wrote: Because cache_get_value_index_int uses column's idx while cache_get_value_name uses literal string. this is my factions code, if u want i can provide the entire code, and the tutorial i read,? Code: enum faction RE: Help with mysql and data retrieving. - Pinch - 2020-11-10 I don't wanna do everything from you because I see you understood nothing, I mean you literally have example scripts in the plugin's github.com repository... RE: Help with mysql and data retrieving. - Expert* - 2020-11-10 U replaced cache_get_data with cache_get_value_index_int. What you want is: new rows; cache_get_row_count( rows ); field count is irelevent to you in this case, so we don't have to know how many we have... Also use this: cache_get_value_name_int(i,"id",Factions[i][ID]); Instead of: cache_get_value_int(i,"id",Factions[i][ID]); |