Help to understand code
#2

A real good step to reading and understanding, is making your code readable, and consistent.

Код:
forward CarCheck();
public CarCheck()
{
	new rows,fields;
	cache_get_data(rows,fields);
	new fetch[24];
	new msg[200];
	if(rows>0)
	{
 		for(new rowas = 0; rowas != rows; rowas++)
		{
			cache_get_field_content(rowas, "Name", fetch);
			format( msg, sizeof(msg), "SELECT * FROM `users` WHERE Name = '%s'",fetch);
			mysql_function_query(MysqlConnection,msg,true,"CarCheck2","s",fetch);
		}
	}
	return 1;
}
Код:
forward CarCheck2(name[]);
public CarCheck2(name[])
{
	new rows,fields;
	cache_get_data(rows,fields);
	new msg[200];
	if(rows==0)
	{
 		format( msg,sizeof( msg ),"DELETE FROM `cars` WHERE  Name = '%s'",Name);
 		mysql_function_query(MysqlConnection,msg,false,"","");
		return 1;
	}
	return 1;
}
Looks a lot better and readable.

Now, if you put in some print statements, you'll get some more info back.

PHP код:
forward CarCheck();
public 
CarCheck()
{
    new 
rows,fields;
    
cache_get_data(rows,fields);
    new 
fetch[24];
    new 
msg[200];
    if(
rows>0)
    {
         for(new 
rowas 0rowas != rowsrowas++)
        {
            
cache_get_field_content(rowas"Name"fetch);
            
formatmsgsizeof(msg), "SELECT * FROM `users` WHERE Name = '%s'",fetch);
            
printf('CarCheck for %s'fetch);
            
mysql_function_query(MysqlConnection,msg,true,"CarCheck2","s",fetch);
        }
    }
    return 
1;

PHP код:
forward CarCheck2(name[]);
public 
CarCheck2(name[])
{
    new 
rows,fields;
    
cache_get_data(rows,fields);
    new 
msg[200];
    if(
rows==0)
    {
         
formatmsg,sizeofmsg ),"DELETE FROM `cars` WHERE  Name = '%s'",Name); //This won't fire, due to name, not Name....???
        
printf('CarCheck2 (Deletion) for %s'name);
         
mysql_function_query(MysqlConnection,msg,false,"","");
        return 
1;
    }
    return 
1;

Mind out for mixing variable methods. UPPERCASE, lowercase, Capitalized and all that. Keep it consistent from the start, and you'll find it easier to pick up where you left off in the future.
Reply


Messages In This Thread
Help to understand code - by ,TomY' - 04.08.2018, 10:21
Re: Help to understand code - by Sew_Sumi - 04.08.2018, 10:31
Re: Help to understand code - by ,TomY' - 04.08.2018, 10:39
Re: Help to understand code - by Sew_Sumi - 04.08.2018, 10:41
Re: Help to understand code - by ,TomY' - 04.08.2018, 10:49
Re: Help to understand code - by Sew_Sumi - 04.08.2018, 11:03
Re: Help to understand code - by ,TomY' - 04.08.2018, 11:24
Re: Help to understand code - by Sew_Sumi - 04.08.2018, 15:42

Forum Jump:


Users browsing this thread: 1 Guest(s)