Jump to content
  • 0

Comanda lideri multipli


Sealand123

Question

Problema intalnita (descriere): Am facut o comanda care imi arata liderii online, merge dar daca sunt mai multi lideri online ce pot sa ac pentru ca il afiseaza doar pe primul.
Ero(area / rile) / warning-(ul / urile): -
Liniile de cod / sursa / script-ul(obligatoriu):

 if(strcmp(cmd, "/liderii2", true) == 0)
    {
        new result[100],offleader[100],string[300];
        mysql_query("SELECT NULL FROM players WHERE Leader='2'");
        mysql_store_result();
        mysql_free_result();
        format(string, sizeof(string), "In total avem %d Lideri la factiunea doi",mysql_num_rows(););
        SendClientMessage(playerid,-1,string);

        format(string,100,"SELECT `username` FROM `players` WHERE `Leader`='2'");
        mysql_query(string);
        mysql_store_result();
        if(mysql_retrieve_row ())
        {
              mysql_fetch_field_row(result, "username"); strmid(offleader, result, 0, 255, 255);
              format(string, sizeof(string), "Numele liderului la factiunea 2 este %s",offleader);
            SendClientMessage(playerid,-1,string);
        }
    }


Imagini / Video (optional): -
Ati incercat sa rezolvati singur?:   

Am adaugat asta

else if(mysql_retrieve_row () == 2)
        {
            	mysql_fetch_field_row(result, "username"); strmid(offleader, result, 0, 255, 255);
  			format(string, sizeof(string), "Numele liderului la factiunea 2 este %s",offleader);
			SendClientMessage(playerid,-1,string);
        }

Dar il afiseaza tot pe acela

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Inlocuieste verificarea (if)

if(mysql_retrieve_row ())

cu acest cat timp (while)

while(mysql_retrieve_row ())

Tu acolo verificai doar daca exista rezultat si il luat doar pe primul aparut in interogare, asa cu acest cat timp (while) le iei pe toate.

 

P.S: Dupa ce iese din acel cat timp executa si http://wiki.sa-mp.com/wiki/MySQL#mysql_free_result sa eliberezi rezultatele.

  • Upvote 1
Link to comment
Share on other sites

  • 0

Cu placere.

While asa este nu m-am gandit ca pot folosi while pentru asta.

Multumesc WopsS   Acum merge bine afiseaza toti liderii.

Dar am o intrebare ce se intampla daca nu pun   mysql_free_result();  ?

 

Dupa ce stochezi rezultatul cu mysql_store_result il pastrezi in memorie, ca sa eliberezi acel spatiu din memorie trebuie sa chemi mysql_free_result.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more details you can also review our Terms of Use and Privacy Policy.