[MYSQL]Delete row
#1

I have a little question.How i make to delete row from MYSQL table->cars when player sell the personal vehicle?
Is a rpg server.
Part of script:
Original script
Код:
if(dialogid == 145)
		{
		if(response==1){
					      if(PlayerData[playerid][pPcarkey] == 999)
							{
							return 1;
							}
				new carkey = PlayerData[playerid][pPcarkey];
				
				new query[MAX_STRING];
						new idd =  PlayerData[playerid][pPcarkey];
						
							new model = GetVehicleModel(carkey+PreVehicle);
						  CarData[idd][cLocationx] = 289.1124+random(5);
						CarData[idd][cLocationy] = -1528.9996+random(5);
						CarData[idd][cLocationz] = 24.4255+random(1);
			
					
						
					format(query, sizeof(query), "UPDATE cars SET Locationx='%f' WHERE id=%d", CarData[idd][cLocationx], idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET Locationy='%f' WHERE id=%d", CarData[idd][cLocationy], idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET Locationz='%f' WHERE id=%d", CarData[idd][cLocationz], idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET Angle='0' WHERE id=%d", idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET SaLocationx='%f' WHERE id=%d", CarData[idd][cLocationx], idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET SaLocationy='%f' WHERE id=%d", CarData[idd][cLocationy], idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET SaLocationz='%f' WHERE id=%d", CarData[idd][cLocationz], idd);
						mysql_query(query);
						format(query, sizeof(query), "UPDATE cars SET SaAngle='0' WHERE id=%d", idd);
						mysql_query(query);

				format(query, sizeof(query), "UPDATE cars SET Owned='0' WHERE id=%d", PlayerData[playerid][pPcarkey]);
                mysql_query(query);
			
				format(query, sizeof(query), "UPDATE cars SET Owner='Dealership' WHERE id=%d", PlayerData[playerid][pPcarkey]);
				mysql_query(query);
				DestroyVehicle(carkey+PreVehicle);
				
					CreateVehicle(model, CarData[idd][cLocationx], CarData[idd][cLocationy], CarData[idd][cLocationz],0, 0, 0, 0);
				new price = floatround((0.7 * CarData[carkey][cValue]), floatround_round);
				CarData[carkey][cValue] = price;
				
				GivePlayerCash(playerid, price);
				format(query, sizeof(query), "UPDATE cars SET Value='%d' WHERE id=%d", CarData[carkey][cValue], PlayerData[playerid][pPcarkey]);
				mysql_query(query);
				format(query, sizeof(query), "UPDATE players SET Car='999' WHERE id=%d", PlayerData[playerid][pSQLID]);
				mysql_query(query);
				SendClientMessage(playerid,COLOR_WHITE,"You sold your car");
				CarData[carkey][cOwned] = 0;
				PlayerData[playerid][pPcarkey] = 999;
		}
		}
My script:
Код:
if(dialogid == 145)
		{
		if(response==1){
					      if(PlayerData[playerid][pPcarkey] == 999)
							{
							return 1;
       }
   	new carkey = PlayerData[playerid][pPcarkey];

				DestroyVehicle(carkey+PreVehicle);

				new price = floatround((0.7 * CarData[carkey][cValue]), floatround_round);
				CarData[carkey][cValue] = price;
				
				GivePlayerCash(playerid, price);
				SendClientMessage(playerid,COLOR_WHITE,"You sold your car.");
				PlayerData[playerid][pPcarkey] = 999;
		}
		}
(Delete from game but no from mysql table.)
I need de delete car(destroy), no create.
Thanks.
Reply
#2

This is just a simple mysql query. Example
In your case it would be something like
pawn Код:
format(query,128,"DELETE FROM vehicle_table WHERE carid='%d'",CarID);
As I don't know the names of the fields in the cars table, I'm not sure what exactly the query would be, but deleting a row in general is just like the above.
Reply
#3

Thanks very much.Solved
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)