Load MYSQL and put in order - 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: Load MYSQL and put in order (
/showthread.php?tid=632377)
Load MYSQL and put in order -
weex - 13.04.2017
I have a items system but when restart the server i need to set on order
For example if:
Код:
itemLIST 15 is itemID 11
itemLIST 16 is itemID 0
itemLIST 17 is itemID 0
itemLIST 18 is itemID 25
On load, i need to change to:
Код:
itemLIST 15 is itemID 11
itemLIST 16 is itemID 25 (from 18)
I've tried this OrderItems(), but after add it i can't load...
It printing:
Код:
[21:13:34] =================
[21:13:34] ordenar items
[21:13:34] =================
[21:13:34] itemloop [0] itemID [15]
[21:13:34] itemloop [0] itemID [16]
[21:13:34] itemloop [0] itemID [17]
[21:13:34] itemloop [0] itemID [18]
[21:13:34] itemloop [0] itemID [19]
[21:13:34] itemloop [0] itemID [20]
And if i remove OrderItems() load right, with no order ofc
PHP код:
LoadItems() {
new listloop = ServerStoreItems + 1;
while(listloop < MAX_LISTS) {
new query[50]; // Nгo precisa ser enorme como vocк tinha colocado; Precisa apenas caber sua query dentro dela
mysql_format(ConnectMYSQL, query, sizeof(query), "SELECT * FROM items WHERE itemLIST = '%d'", listloop);
mysql_tquery(ConnectMYSQL, query, "Load_Items", "i", listloop);
listloop++;
}
OrderItems();
}
forward Load_Items(listloop); public Load_Items(listloop) {
new rows, fields;
cache_get_row_count(rows);
cache_get_field_count(fields);
if(rows) {
// ints
cache_get_value_int(0, "itemID", ItemInfo[listloop][itemID]);
}
}
forward OrderItems(); public OrderItems() {
printf("=================");
printf("ordenar items");
printf("=================");
new lastitem = ServerStoreItems+1;
for(new itemloop = ServerStoreItems+1; itemloop < MAX_LISTS; itemloop++) {
printf("itemloop [%i] itemID [%i]", ItemInfo[itemloop][itemID], itemloop);
if(ItemInfo[itemloop][itemID] > 0) {
lastitem++;
printf("lastitem [%i]", lastitem);
ItemInfo[lastitem][itemID] = ItemInfo[itemloop][itemID];
new squery[2500];
mysql_format(ConnectMYSQL, squery, sizeof(squery), "UPDATE `items` SET `itemID` = '%d' WHERE itemLIST = '%d'",
ItemInfo[lastitem][itemID],
lastitem);
mysql_pquery(ConnectMYSQL, squery);
}
}
}
Re: Load MYSQL and put in order -
weex - 23.04.2017
Anybody know how to make it to order?
Re: Load MYSQL and put in order -
Vince - 23.04.2017
Can't you just use "ORDER BY" in the query?
Re: Load MYSQL and put in order -
weex - 23.04.2017
I think this function don't solve my problem
I'll try to explain better:
I have a item system in my server.. it have to start 1 and finish on 100 but the item model can not be 0 when server start it need to be ordered
For example:
ID | MODEL
1 | 120
2 | 130
3 | 0
4 | 150
I need to make a order to when a model of a item be 0, the values of the next id, be moved like:
ID | MODEL
1 | 120
2 | 130
3 | 150
4 | 0
Re: Load MYSQL and put in order -
weex - 28.04.2017
bump, post edited