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



MySQL. - JoelR - 27.12.2012

Hello. I'm creating something with my MySQL information and I want it to be displayed all in one.


Say, I have:

pawn Код:
new query[128];
format(query, sizeof(query), "SELECT * FROM `admins` WHERE `adminid` = 2");
mysql_query(query);
How could I display every result set that comes from it using MySQL R6?

I was thinking about the PHP mysql_fetch_array, but it's different obviously.

Thanks.


Re: MySQL. - Peach - 27.12.2012

You'd want to check and see if there were any rows available through the query by using: mysql_num_rows and then if the query was a success use mysql_get_field and go from there either placing the data into a dialog or string of text.


Re: MySQL. - JoelR - 27.12.2012

Thank you! I'll give that a shot.


Re: MySQL. - JoelR - 27.12.2012

I'm still having a problem with this. Can't seem to get it working, please could you give me an example displayed on a dialog?

Thanks!

Edit: Was meant to be an edit sorry


Re: MySQL. - Peach - 27.12.2012

Just a quick example I wrote for you, this is completely untested but should give you a rough idea of what you're expecting.

pawn Код:
public LoadAdmins()
{
    new admins[250], query[100];
    format(query, sizeof(query), "SELECT * FROM `admins` WHERE `adminid` = '2' LIMIT 25"); // LIMIT OF 25.
    mysql_query(query);
    mysql_store_result();
    new numberofadmins = mysql_num_rows();
    for(new admins = 0; admins < numberofadmins; admins++)
    {
        while(mysql_retrieve_row())
        {
            mysql_fetch_field_row(admins, "Name"); /* Variables here */ = strval(admins);
            mysql_fetch_field_row(admins, "Adminlevel"); /* Variables here */ = strval(admins);
            admins ++;
        }
    }
    mysql_free_result();
    return true;
}



Re: MySQL. - JoelR - 27.12.2012

pawn Код:
new admins[250], query[100], name[24], rank, online, string[256];  
format(query, sizeof(query), "SELECT * FROM admins WHERE alevel= 2");
mysql_query(query);
mysql_store_result();
new numberofadmins = mysql_num_rows();
for(new admins1 = 0; admins1 < numberofadmins; admins1++)
{
    while(mysql_retrieve_row())
    {
        mysql_fetch_field_row(admins, "uname"); format(name, sizeof(name), "%s", admins);
        mysql_fetch_field_row(admins, "alevel"); rank = strval(admins);
        mysql_fetch_field_row(admins, "onlinestatus"); online = strval(admins);
        admins1 ++;
    }
}
mysql_free_result();

format(string, sizeof(string), "%s\n%s (Level: %d Online: %d)", string, name, rank, online);
ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_LIST, "Admins", string, "OK", "");
That's not working.

It displays the first person in it at that's it.


Re: MySQL. - Unte99 - 27.12.2012

It would be best for you to analyze the for loop. Search in the wiki or somewhere else for some examples. When you get to work the loop correctly, you will need strins(ert) function to add to the dialog string the admins strings.


Re: MySQL. - JoelR - 27.12.2012

I have no clue of this please could you help me?


Re: MySQL. - JoelR - 28.12.2012

Anyone? It's important.


Re: MySQL. - [HiC]TheKiller - 28.12.2012

pawn Код:
new adminstring[1024]/*Make the string as small as possible ;)*/, name[24], rank, online, string[10];  
mysql_query("SELECT * FROM admins WHERE alevel= 2");
mysql_store_result();
new numberofadmins = mysql_num_rows();
format(adminstring, sizeof(adminstring) "{FF0000}Current admins: %d{FFFFFF}\n", numberofadmins);
while(mysql_retrieve_row())
{
    mysql_fetch_field_row(name, "uname");
    mysql_fetch_field_row(string, "alevel"); rank = strval(string);
    mysql_fetch_field_row(string, "onlinestatus"); online = strval(string);
    format(adminstring, sizeof(adminstring), "%s\n%s (Level: %d Online: %d)", adminstring, name, rank, online);
}
mysql_free_result();
ShowPlayerDialog(playerid, 9999, DIALOG_STYLE_LIST, "Admins", adminstring, "OK", "");
Give that a go.