SA-MP Forums Archive
MySQL code not working. - 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 code not working. (/showthread.php?tid=595806)



MySQL code not working. - The__ - 08.12.2015

pawn Код:
format(mysql, sizeof(mysql), "SELECT * FROM `warrants` WHERE `Suspect` = '%s' ORDER BY `ID` DESC", SQL_ReturnEscaped(ReturnName(userid)));
        mysql_function_query(g_iHandle, mysql, true, "", "ds", playerid, ReturnName(userid));
        printf("%s",mysql);
        cache_get_data(rows, fields, g_iHandle);
        string[0] = 0;
        for (new i = 0; i < rows; i ++)
        {
            cache_get_field_content(i, "Description", desc, g_iHandle,128);
            cache_get_field_content(i, "Date", date, g_iHandle,128);
            format(string, sizeof(string), "%s%s (%s)\n", string, desc, date);
        }
        format(desc, sizeof(desc), "Charges: %s", ReturnName(userid));
        Dialog_Show(playerid, ChargeList, DIALOG_STYLE_LIST, desc, string, "Close", "");
Why wouldn't this work? Sorry for asking.


Re: MySQL code not working. - CrazyChoco - 08.12.2015

Excellent question. Why don't my script work either?

Show you mysql log for this question, and provide us some information. Otherwise it'll be impossible for us to help you.


Re: MySQL code not working. - The__ - 11.12.2015

Okay, the fetching is done correctly, however it's duplicating? I'm not sure why.

Код:
for (new i = 0; i < rows; i ++)
	{
	    cache_get_field_content(i, "Description", desc, g_iHandle,128);
	    cache_get_field_content(i, "Date", date, g_iHandle,128);

	    format(criminal, sizeof(criminal), "%s%s (%s)\n", criminal, desc, date);
	}
Everytime I reopen it, it shows it again, if I open it 3 times, it shows 3 times, ect


Re: MySQL code not working. - Sinox - 11.12.2015

Maybe use

Код:
string[0] = EOS; //EOS = End of string
to empty the string before you format it.


Re: MySQL code not working. - Virtual1ty - 11.12.2015

Edit: I should take a better look on the code before posting next time.


Re: MySQL code not working. - Beckett - 11.12.2015

That's because you're formatting a string and planting the actual string in it.

Look carefully here:

pawn Код:
format(criminal, sizeof(criminal), "%s%s (%s)\n", criminal, desc, date);
If that's not it, I can't tell what because you show us no variables or how you are actually coding that.


Re: MySQL code not working. - The__ - 11.12.2015

Quote:
Originally Posted by Sinox
Посмотреть сообщение
Maybe use

Код:
string[0] = EOS; //EOS = End of string
to empty the string before you format it.
You're the MPV, good sir.