Seeking for help in a simple command
#1

I have created a SQL database for vehicles, it's A-okay yet nothing wrong with it.
Vehicles in the database have a unique ID specified in the DB and when it's spawned it gets another ID from the server(vehicleid).

Now what I specifically want is creating a simple command letting me know the vehicleid by writing on the ID on the database.
And I've added a new field on the DB that saves on the server's vehicle ID once spawned.
So basically I want to enter a field from the DB by a command param and get the other field as an output.

I want it somehow by giving it '249' it outputs '24'.

Here's what I've done, not working yet and I don't know why.
PHP код:
CMD:getservervehid(playeridparams[])
{
    new 
enteredID;
    new 
string[64];
    if (
sscanf(params"d"enteredID)) return SendSyntaxMessage(playerid"/getservervehid[ID]");
    
format(stringsizeof(string), "SELECT * FROM `cars` WHERE `carID` = '%d'"enteredID);
    
mysql_tquery(g_iHandlestring);
    
    static
        
rows,
        
fields;
    
cache_get_data(rowsfieldsg_iHandle);
    for (new 
0rows++) {
        new 
gottenid cache_get_field_int(i"carSrvID");
        
SendServerMessage(playerid"IDgotten > %d."gottenid);
    }
    return 
1;

What's wrong over there? How can I fix this?
Reply
#2

Quote:
Originally Posted by AHN
Посмотреть сообщение
I have created a SQL database for vehicles, it's A-okay yet nothing wrong with it.
Vehicles in the database have a unique ID specified in the DB and when it's spawned it gets another ID from the server(vehicleid).
Here's an image from the DB, for the sake of deep explanation.

And as I said, in the server when it's spawned it gets another ID(vehicleid).

Now what I want is creating a simple command letting me know the vehicleid by writing on the ID on the database.
Here's what I've done:-

On Vehicle Spawn:
Код:
        CarData[carid][carVehicle] = CreateVehicle(CarData[carid][carModel], CarData[carid][carPos][0], CarData[carid][carPos][1], CarData[carid][carPos][2], CarData[carid][carPos][3], CarData[carid][carColor1], CarData[carid][carColor2], (CarData[carid][carOwner] != 0) ? (-1) : (1200000));
        // The spawning line. "CarData[carid][carVehicle]" outputs server's vehicleid.
        CarData[carid][carSrvID] = CarData[carid][carVehicle];
        // Storing server's vehicleid in another column on the database.
I've added a Column in the database to store server's vehicleid when a car spawns `carSrvID`
This works well and stores the ID but what I wrote in the command is the following:

Код:
CMD:getservervehid(playerid, params[])
{
	new enteredID;
	new string[64];
	new gottenid;
	
	if (sscanf(params, "d", enteredID)) return SendSyntaxMessage(playerid, "/getservervehid [ID]");
	
    format(string, sizeof(string), "SELECT * FROM `cars` WHERE `carID` = '%d'", enteredID); //Will select the car with the DB ID.
    mysql_tquery(g_iHandle, string);
    
	gottenid = cache_get_field_int(gottenid, "carSrvID");
	
	SendServerMessage(playerid, "IDgotten > %d.", gottenid);
	return 1;
}
It always outputs 0 on the message. What was specifically wrong on the code above? I still can't figure it out. Hoping that somebody will help me out.
Thanks.
Firstly...
How are you getting the field when you haven't even defined rows & fields..
Try
PHP код:
new rows,fieldsid_stringgottenid;
cache_get_data(rows,fields);
if(
rows >= 1) {
     
cache_get_row(00id_string);
      
gottenid strval(id_string);
} else {
     
printf("0 Rows Found");

The above code is based on a guess that your CARID = your primary key...
So Due to you're selecting a designated ID...
The ROW ID = 0
the Colum (IF ITS YOUR PRIMARY KEY) = 0
Then you store it..
then you assign strval when retrive
Reply
#3

Quote:
Originally Posted by Prokill911
Посмотреть сообщение
Firstly...
How are you getting the field when you haven't even defined rows & fields..
Try
PHP код:
new rows,fieldsid_stringgottenid;
cache_get_data(rows,fields);
if(
rows >= 1) {
     
cache_get_row(00id_string);
      
gottenid strval(id_string);
} else {
     
printf("0 Rows Found");

The above code is based on a guess that your CARID = your primary key...
So Due to you're selecting a designated ID...
The ROW ID = 0
the Colum (IF ITS YOUR PRIMARY KEY) = 0
Then you store it..
then you assign strval when retrive
Thanks for your reply...
I've tried your code and unfortunately did not work.
Код:
CMD:getservervehid(playerid, params[])
{
    new enteredID;
    new string[64];
	
    if (sscanf(params, "d", enteredID)) return SendSyntaxMessage(playerid, "/getservervehid [ID]");
	
    format(string, sizeof(string), "SELECT * FROM `cars` WHERE `carID` = '%d'", enteredID);
    mysql_tquery(g_iHandle, string);
    new rows, fields, id_string, gottenid;
	cache_get_data(rows,fields);
	if(rows >= 1) {
		cache_get_row(0, 1, id_string);
		gottenid = strval(id_string);
                SendServerMessage(playerid, "IDgotten > %d.", gottenid);
	} else {
	     printf("0 Rows Found");
	}
	return 1;
}
And getting argument mismatch for the two lines...
__
Whatsoever. Here's exactly what I want because I feel misunderstanding.
The query will output one row only because it will be only one vehicle with that ID, so the command params is the primary column/field content and I want the output to be the second field, this Image will explain it all

I want it somehow by giving it '249' it outputs '24'. It would be greatly appreciated if you help me getting it to work.
_____
EDIT: Well, after much tries I still don't get it. Can you analyze the following code for me?
Код:
    format(string, sizeof(string), "SELECT * FROM `cars` WHERE `carID` = '%d'", enteredID);
    mysql_tquery(g_iHandle, string);
    
	static
	    rows,
	    fields;

	cache_get_data(rows, fields, g_iHandle);
	for (new i = 0; i < rows; i ++) {
		new gottenid = cache_get_field_int(i, "carSrvID");
		SendServerMessage(playerid, "IDgotten > %d.", gottenid);
	}
Outputs nothing.. what's wrong over there?
Reply
#4

BUMPING(24hrsPassed).. Still in need to fix the code.
Reply
#5

Still unfixed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)