//in the command to insert
new tmpQuery[128];
mysql_format(1, tmpQuery, sizeof(tmpQuery), "INSERT INTO `STREAMS` (`LINK`) VALUES ('%e')", linkStr);
//%e will escape the string and prevent SQL injection
mysql_pquery(1, tmpQuery, "OnInsertStreamFinish", "d", playerid);
//Then you have a callback somewhere else in the code
forward OnInsertStreamFinish(playerid);
public OnInsertStreamFinish(playerid);
{
new num = cache_affected_rows();
if(!num) return SendClientMessage(playerid, 0xFF0000FF, "Error while inserting"); //if num is 0 it failed
else
{
SendClientMessage(playerid, 0x00FF00FF, "Successfully added!");
}
return 1;
}
|
If you're using this MySQL plugin (which you should be) then you just use the function mysql_pquery to send a query which call a callback once the query finishes
Example: Код:
//in the command to insert
new tmpQuery[128];
mysql_format(1, tmpQuery, sizeof(tmpQuery), "INSERT INTO `STREAMS` (`LINK`) VALUES ('%e')", linkStr);
//%e will escape the string and prevent SQL injection
mysql_pquery(1, tmpQuery, "OnInsertStreamFinish", "d", playerid);
//Then you have a callback somewhere else in the code
forward OnInsertStreamFinish(playerid);
public OnInsertStreamFinish(playerid);
{
new num = cache_affected_rows();
if(!num) return SendClientMessage(playerid, 0xFF0000FF, "Error while inserting"); //if num is 0 it failed
else
{
SendClientMessage(playerid, 0x00FF00FF, "Successfully added!");
}
return 1;
}
|
CMD:savemyradio(playerid, params[])
{
ShowPlayerDialog(playerid,DIALOG_Test, DIALOG_STYLE_INPUT, "Stream", "Enter your stream below:", "Save", "Cancel");
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_Test)
{
if(!response) /
{
SendClientMessage(playerid, 0x00FF00FF, "You clicked on cancel.!");
}
else // Pressed ENTER or clicked 'Login' button
{
new tmpQuery[128];
mysql_format(1, tmpQuery, sizeof(tmpQuery), "INSERT INTO `STREAMS` (`LINK`) VALUES ('%e')", linkStr);
//%e will escape the string and prevent SQL injection
mysql_pquery(1, tmpQuery, "OnInsertStreamFinish", "d", playerid);
}
}
return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
}
|
Here's what I understood, and tried to make.
Код:
CMD:savemyradio(playerid, params[])
{
ShowPlayerDialog(playerid,DIALOG_Test, DIALOG_STYLE_INPUT, "Stream", "Enter your stream below:", "Save", "Cancel");
return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_Test)
{
if(!response) /
{
SendClientMessage(playerid, 0x00FF00FF, "You clicked on cancel.!");
}
else // Pressed ENTER or clicked 'Login' button
{
new tmpQuery[128];
mysql_format(1, tmpQuery, sizeof(tmpQuery), "INSERT INTO `STREAMS` (`LINK`) VALUES ('%e')", linkStr);
//%e will escape the string and prevent SQL injection
mysql_pquery(1, tmpQuery, "OnInsertStreamFinish", "d", playerid);
}
}
return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
}
How can I call this data to load on the /myradio dialog and play it using PlayAudioStream.? |
mysql_pquery(1, "SELECT `LINK` FROM `STREAMS`", "OnLoadStreamsFinish");
forward OnLoadStreamsFinish();
public OnLoadStreamsFinish()
{
new num = cache_get_row_count(); //gets number of rows (streams) returned by the SQL query
if(num) //if number of streams isn't 0
{
new streams[10][128]; //array of 10 strings (128 chars each) - for demonstration purposes
for(new i = 0; i < num; i++)
{
cache_get_row(i, 0, stream[i]);
//saves the first (and, in this case, only) column "LINK" into this array
//should be a global if you want to use it elsewhere in the code
}
}
return 1;
}