SA-MP Forums Archive
MySQL Delete query - 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)
+--- Thread: MySQL Delete query (/showthread.php?tid=613079)



MySQL Delete query - Ahmed21 - 24.07.2016

Hello everyone, I have made a command to remove a row from my "notes" table.
Everything works well, and when I do the command, it sends me a message: u have removed note ID [note id].. and if I enter an invalid note ID it tells that it's invalid. The only problem is that it doesn't remove the note, here's my removing note script:

PHP код:
forward RemoveNoteFunc(playerid);
public 
RemoveNoteFunc(playerid)
{
    new
        
rows,
        
fields;
    
cache_get_data(rowsfieldsmysql);
    
    if(
rows)
    {
        new 
madebythenoteidquery[128];
        
madeby cache_get_row_int(05);
        
thenoteid cache_get_row_int(00);
        if(
pInfo[playerid][Admin] < && pInfo[playerid][ID] != madeby) return SendErrorMSG(playerid"You cannot remove a note unless it's made by you.");
        new 
string[128];
        
mysql_format(mysqlquerysizeof(query), "DELETE * FROM notes WHERE `ID` = %d"thenoteid);
        
mysql_tquery(mysqlquery"""");
        
format(stringsizeof(string), "You have removed note ID %d."thenoteid);
        
SendAdminMSG(playeridstring);
        
format(stringsizeof(string), "%s(%d) has removed note ID %d."PlayerName(playerid), playeridthenoteid);
        
SendALogMSG(string);
    }
    else
    {
         
SendErrorMSG(playerid"Invalid note ID.");
    }
    return 
1;




Re: MySQL Delete query - Konstantinos - 24.07.2016

https://sampwiki.blast.hk/wiki/MySQL/R33..._affected_rows

You can see how many rows were affected and if it is not 0, show the messages about removing note ID.
I'm not entirely sure if there is only one row, if the function returns 0. The note box in wiki states a DELETE query without WHERE clause.

I guess you execute a query to get the the note ID from another table, right? This can be done in one query.


Re: MySQL Delete query - Ahmed21 - 24.07.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/MySQL/R33..._affected_rows

You can see how many rows were affected and if it is not 0, show the messages about removing note ID.
I'm not entirely sure if there is only one row, if the function returns 0. The note box in wiki states a DELETE query without WHERE clause.

I guess you execute a query to get the the note ID from another table, right? This can be done in one query.
So if it's an invalid note ID, the "cache_affected_rows" will return 0?


Re: MySQL Delete query - Konstantinos - 24.07.2016

Quote:
Originally Posted by Ahmed21
Посмотреть сообщение
So if it's an invalid note ID, the "cache_affected_rows" will return 0?
Yes because no rows will be deleted (affected).


Re: MySQL Delete query - Ahmed21 - 24.07.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Yes because no rows will be deleted (affected).
Okay great thank you so much! +REP'd :P