MySQL.
#1

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.
Reply
#2

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.
Reply
#3

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 (       );
Reply
#4

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.
Reply
#5

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. :/
Reply
#6

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

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
Reply
#8

This just example. You can select from your table
Reply
#9

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
Reply
#10

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.....
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)