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



MySQL returning multiple rows - .EnjatsRed. - 06.08.2014

Hello, guys! I'm having some trouble loading multiple rows from database. For example I want to select and store the users with same IP, this is what i've done so far but no result:

Код:
if(strcmp(cmd, "/trackip", true) == 0)
	{
	    if(AdminSecurity[playerid] == 0) return SEM(playerid);
    	tmp = strtok(cmdtext, idx);
    	new qwe[128],zxc[128], string11[256];
    	format(qwe, sizeof(qwe), "%s",tmp);
		format(string11, sizeof(string11), "SELECT IP,username,LastON FROM players WHERE IP = '%s'", qwe);
		mysql_query(string11);
		mysql_store_result();
        new rows = mysql_num_rows();
        mysql_free_result();
        while(mysql_retrieve_row())
        {
            new infoq[3][64];
            mysql_fetch_field_row(zxc, "username"); format(infoq[0], 64, zxc);
        	mysql_fetch_field_row(zxc, "IP"); format(infoq[1], 64, zxc);
        	mysql_fetch_field_row(zxc, "LastON"); format(infoq[2], 64, zxc);
        	format(string, sizeof(string), "Player %s, last logged on %s, IP: %s.", infoq[0], infoq[2], infoq[1]);
        	SCM(playerid, COLOR_WHITE, string);
        	idx++;
		}
	}



Re: MySQL returning multiple rows - paulommu - 06.08.2014

Of course, you're freeing the result before you retrieve the rows. Put 'mysql_free_result();' only at the end of the command.


Re: MySQL returning multiple rows - .EnjatsRed. - 06.08.2014

Yeah man .. you're the best.