SA-MP Forums Archive
Problem loading properties with 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem loading properties with mysql (/showthread.php?tid=278330)



Problem loading properties with mysql - Willow - 21.08.2011

Hi, today I made a simple mysql property system, the problem is these properties won't load.

My code is:

Code:
public LoadProperties()
{
	new query[300];
	format(query,sizeof(query),"SELECT * FROM properties");
	mysql_query(query);
	mysql_store_result();
	new rows = mysql_num_rows();
	for(new i; i < MAX_BIZZ; i++)
	{
	    if(rows)
	    {
			sscanf(query,"ds[50]s[24]ddddffffff",
			Bizz[i][id],
			Bizz[i][name],
			Bizz[i][owner],
			Bizz[i][status],
			Bizz[i][type],
			Bizz[i][vault],
			Bizz[i][interior],
			Bizz[i][intx],
			Bizz[i][inty],
			Bizz[i][intz],
			Bizz[i][outx],
			Bizz[i][outy],
			Bizz[i][outz]);
			
			new
				x,
				y,
				z,
				label[150],
				btype[24];
				
			Bizz[i][outx] = x;
			Bizz[i][outy] = y;
			Bizz[i][outz] = z;
			
			if(Bizz[i][type] == 0) { btype = "n/a"; }
			else if(Bizz[i][type] == 1) { btype = "Shop";}
			
			if(Bizz[id][status] == 1)
			{
			    format(label,sizeof(label),"%s\nOwner: %s | Type: %s\nStatus: Open | ID: %d",Bizz[i][name],Bizz[i][owner],i);
   				Create3DTextLabel(label,0x008080FF,x,y,z,40.0,0);
   			}
   			else
   			{
				if(strval(Bizz[id][owner]))
				{
				    format(label,sizeof(label),"%s\nOwner: %s | Type: %s\nStatus: Closed | ID: %d",Bizz[i][name],Bizz[i][owner],i);
   					Create3DTextLabel(label,0x008080FF,x,y,z,40.0,0);
			    }
			    else
			    {
			        format(label,sizeof(label),"%s\nOwner: %s | Type: %s\nStatus: Closed | ID: %d",Bizz[i][name],Bizz[i][owner],i);
   					Create3DTextLabel(label,0x008080FF,x,y,z,40.0,0);
				}
			}
			printf("bizz %d loaded!",i);
			PrintPropertyStats(i);
		}
		else print("no rows");
	}
	mysql_free_result();
	return 1;
}
Mysql log reported everything correctly..
I am afraid the problem is in mysql_num_rows() or sscanf, can someone help?


Re: Problem loading properties with mysql - [HiC]TheKiller - 21.08.2011

You are not even retrieving the row in the first place and what exactly does the loop do?

mysql_fetch_row
pawn Code:
public LoadProperties()
{
    new query[300], i;
    format(query,sizeof(query),"SELECT * FROM properties");
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row(query))
    {
            sscanf(query,"p|ds[50]s[24]ddddffffff",
            Bizz[i][id],
            Bizz[i][name],
            Bizz[i][owner],
            Bizz[i][status],
            Bizz[i][type],
            Bizz[i][vault],
            Bizz[i][interior],
            Bizz[i][intx],
            Bizz[i][inty],
            Bizz[i][intz],
            Bizz[i][outx],
            Bizz[i][outy],
            Bizz[i][outz]);
           
            new
                x,
                y,
                z,
                label[150],
                btype[24];
               
            Bizz[i][outx] = x;
            Bizz[i][outy] = y;
            Bizz[i][outz] = z;
           
            if(Bizz[i][type] == 0) { btype = "n/a"; }
            else if(Bizz[i][type] == 1) { btype = "Shop";}
           
            if(Bizz[id][status] == 1)
            {
                format(label,sizeof(label),"%s\nOwner: %s | Type: %s\nStatus: Open | ID: %d",Bizz[i][name],Bizz[i][owner],i);
                Create3DTextLabel(label,0x008080FF,x,y,z,40.0,0);
            }
            else
            {
                if(strval(Bizz[id][owner]))
                {
                    format(label,sizeof(label),"%s\nOwner: %s | Type: %s\nStatus: Closed | ID: %d",Bizz[i][name],Bizz[i][owner],i);
                    Create3DTextLabel(label,0x008080FF,x,y,z,40.0,0);
                }
                else
                {
                    format(label,sizeof(label),"%s\nOwner: %s | Type: %s\nStatus: Closed | ID: %d",Bizz[i][name],Bizz[i][owner],i);
                    Create3DTextLabel(label,0x008080FF,x,y,z,40.0,0);
            }
            printf("bizz %d loaded!",i);
            PrintPropertyStats(i);
                        i++;
        }
        mysql_free_result();
        return 1;
}



Re: Problem loading properties with mysql - Willow - 21.08.2011

Thanks, but now only first one loads... and the float variable is 0.0000