SA-MP Forums Archive
MySQL. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: MySQL. (/showthread.php?tid=264578)



MySQL. - BaubaS - 26.06.2011

pawn Код:
new
    Query[ 56 ]
;

format            ( Query, 51, "SELECT * FROM `playersdb` ORDER BY `Job` = '%d'", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
SendClientMessage ( playerid, -1, mysql_num_rows( ) );
mysql_free_result (       );

format            ( Query, 56, "SELECT `Name` FROM `playersdb` ORDER BY `Job` = '%d'", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
SendClientMessage ( playerid, Query );
mysql_free_result (       );
Is this will work? From first query I want to know how much more people there are in that job, and from second query I want to their names. Sorry for bad indentation, forum fucked it up.


Re: MySQL. - [HiC]TheKiller - 26.06.2011

I don't think that would work =/.

This should though
pawn Код:
new
    Query[ 56 ]
;

format            ( Query, 51, "SELECT * FROM `playersdb` WHERE `Job` = '%d'", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
SendClientMessage ( playerid, -1, mysql_num_rows( ) );
mysql_free_result (       );

format            ( Query, 56, "SELECT `Name` FROM `playersdb` WHERE `Job` = '%d'", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
new str[50];
format(str, sizeof(str), "Your job is ID %d",  mysql_fetch_int());
SendClientMessage ( playerid, str);
mysql_free_result (       );
Order by only orders the columns into a certain value, not selects them. The WHERE statement chooses the rows fitting your query and stores them. The functions mysql_fetch_int fetches the single integer value stored in a string.


Re: MySQL. - Donya - 26.06.2011

i think that might not work either. if it doesn't try this

pawn Код:
new
    Query[ 56 ]
;

format            ( Query, 51, "SELECT * FROM `playersdb` WHERE `Job` = %d", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
SendClientMessage ( playerid, -1, mysql_num_rows( ) );
mysql_free_result (       );

new Name[MAX_PLAYER_NAME], Escape[24];
GetPlayerName(playerid, Name, 24);
mysql_real_escape_string(Name, Escape);
format            ( Query, 56, "SELECT `Job` FROM `playersdb` WHERE `Name` = '%s' LIMIT 1", Escape );
mysql_query       ( Query );
mysql_store_result(       );
new str[50];
format(str, sizeof(str), "Your job is ID %d",  mysql_fetch_int());
SendClientMessage ( playerid, str);
mysql_free_result (       );



Re: MySQL. - [HiC]TheKiller - 27.06.2011

Quote:
Originally Posted by Donya
Посмотреть сообщение
i think that might not work either. if it doesn't try this

pawn Код:
new
    Query[ 56 ]
;

format            ( Query, 51, "SELECT * FROM `playersdb` WHERE `Job` = %d", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
SendClientMessage ( playerid, -1, mysql_num_rows( ) );
mysql_free_result (       );

new Name[MAX_PLAYER_NAME], Escape[24];
GetPlayerName(playerid, Name, 24);
mysql_real_escape_string(Name, Escape);
format            ( Query, 56, "SELECT `Job` FROM `playersdb` WHERE `Name` = '%s' LIMIT 1", Escape );
mysql_query       ( Query );
mysql_store_result(       );
new str[50];
format(str, sizeof(str), "Your job is ID %d",  mysql_fetch_int());
SendClientMessage ( playerid, str);
mysql_free_result (       );
This is correct, I didn't really read what he was trying to do.


Re: MySQL. - BaubaS - 27.06.2011

First query is okay, but second. No, I want to know people names in my job, not my job ID.

For example, there is command "/job". Job id is 2, and in job id 2 there are 2 ppl more, but they're offline: abc_123, test_test. And I want to get that names from MySQL. So, yes, I want to get all ppl names which job is 2, even they're offline. Its possible with MySQL. :/


Re: MySQL. - Raimis_R - 27.06.2011

Write something like
PHP код:
SELECT `NameFROM `jobsWHERE `jobid` = '%i' 



Re: MySQL. - BaubaS - 27.06.2011

Quote:
Originally Posted by Raimis_R
Посмотреть сообщение
Write something like
PHP код:
SELECT `NameFROM `jobsWHERE `jobid` = '%i' 
And I will need to create a table for jobs? o_O


Re: MySQL. - Raimis_R - 27.06.2011

This just example. You can select from your table


Re: MySQL. - WooTFTW - 27.06.2011

pawn Код:
new read_data[24];

format            ( Query, 56, "SELECT `Name` FROM `playersdb` ORDER BY `Job` = '%d'", pData[ playerid ][ pJob ] );
mysql_query       ( Query );
mysql_store_result(       );
while(mysql_fetch_row(read_data))
{
    SendClientMessage ( playerid, read_data );
}
mysql_free_result (       );
This should work. I am not used to script with spaces, so you might want to space it by yourself


Re: MySQL. - BaubaS - 27.06.2011

I will test it soon, but even it will work, is that hard to make new line in dialog for each name? I mean

first name from mysql\nsecond name from mysql\n.....