(Crashes script) Trying to get ALL MySQL results. -
Dokins - 08.03.2012
This doesnt work, but what I'm trying to do is...
type: /findnumber Grant.
It should check the mysql for all results in that field with the name "Grant" but display the full name.
i.e I search "Grant" and it shows me all the names that begin with or end with Grant.
like
Grant_McCaw
Grant_Johnson
Adrian_Grant.
Etc.
pawn Код:
CMD:findnumber(playerid, params[])
{
if(LoggedIn[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
if(Phonebook[playerid] == 0) return SendClientMessage(playerid, COLOUR_GREY, "You do not have a phonebook, you can buy one from a store.");
new player[24],string[128], query[256], result[24];
if(sscanf(params, "s[24]",player)) return SendClientMessage(playerid, COLOUR_GREY, "Usage: /findnumber [player name]");
format(query, sizeof(query), "SELECT `Number` FROM `accounts` WHERE `PlayerName` LIKE '%s%%%'", player);
mysql_query(query); // No query line
mysql_store_result(); // "Error nothing to store"
new rows = mysql_num_rows();
while(mysql_retrieve_row()) //this will be running until all rows are processed
{
mysql_fetch_field(rows, result);
}
new msnum = mysql_fetch_int();
if(rows > 0)
{
format(string, sizeof(string), "%s - %d",result, msnum);
SendClientMessage(playerid, COLOUR_WHITE, string);
}
if(rows == 0)
{
SendClientMessage(playerid, COLOUR_GREY, "There was no numbers found with that name.");
}
mysql_free_result();
return 1;
}
Re: (Crashes script) Trying to get ALL MySQL results. -
MadeMan - 08.03.2012
pawn Код:
format(query, sizeof(query), "SELECT `Number` FROM `accounts` WHERE `PlayerName` LIKE '%%%s%%'", player);
mysql_query(query);
mysql_store_result();
new rows = mysql_num_rows();
if(rows == 0)
{
SendClientMessage(playerid, COLOUR_GREY, "There was no numbers found with that name.");
}
else
{
new msnum = mysql_fetch_int();
format(string, sizeof(string), "%s - %d",player, msnum);
SendClientMessage(playerid, COLOUR_WHITE, string);
}
mysql_free_result();
Re: (Crashes script) Trying to get ALL MySQL results. -
Dokins - 08.03.2012
Won't that only display "Grant" for each row?
Re: (Crashes script) Trying to get ALL MySQL results. -
Dokins - 08.03.2012
That only displays "Grant - (NUMBER)" How can I make it display the full name?
Re: (Crashes script) Trying to get ALL MySQL results. -
MadeMan - 08.03.2012
Quote:
Originally Posted by Dokins
Won't that only display "Grant" for each row?
|
Yeah, sorry.
pawn Код:
format(query, sizeof(query), "SELECT `PlayerName`,`Number` FROM `accounts` WHERE `PlayerName` LIKE '%%%s%%'", player);
mysql_query(query);
mysql_store_result();
new bool:matches=false;
while(mysql_next_row())
{
matches=true;
mysql_get_field("Number",result);
new msnum = strval(result);
mysql_get_field("PlayerName",result);
format(string, sizeof(string), "%s - %d", result, msnum);
SendClientMessage(playerid, COLOUR_WHITE, string);
}
if(!matches)
{
SendClientMessage(playerid, COLOUR_GREY, "There was no numbers found with that name.");
}
mysql_free_result();
Re: (Crashes script) Trying to get ALL MySQL results. -
Dokins - 08.03.2012
Just going to test it, I was actually almost there aha.
Re: (Crashes script) Trying to get ALL MySQL results. -
Dokins - 08.03.2012
Perfect, thanks!