mysql random cp
#1

hy
how to create a database checkpoint random?
Reply
#2

PHP код:
SELECT FROM table ORDER BY RAND() LIMIT 1
Reply
#3

Sorry for 'hijacking' your thread, David. But I have a question. What does LIMIT 1 do?
Reply
#4

Quote:
Originally Posted by newbienoob
Посмотреть сообщение
Sorry for 'hijacking' your thread, David. But I have a question. What does LIMIT 1 do?
LIMIT 1 > So you will get only 1 row from a table.
Reply
#5

why is it wrong?

Код:
public NewCP()
{
	new posx[10],posy[10],posz[10];
    format(g_szQuery, sizeof g_szQuery, "SELECT * FROM cp ORDER BY RAND() LIMIT 1;");
    mysql_function_query(1, g_szQuery, false, "OnQueryFinish", "");
    cache_get_row(0, 3, posx);
	cache_get_row(0, 4, posy);
    cache_get_row(0, 5, posz);
	SendFormatMessage(-1,RED,"asd: %f,  %f , %f",posx,posy,posz);
	return 1;
}
Reply
#6

You must use cache to get data and change the false to true.

Full example:
pawn Код:
stock NewCP()
            {
                format(g_szQuery, sizeof g_szQuery, "SELECT * FROM cp ORDER BY RAND() LIMIT 1;");
                mysql_function_query(1, g_szQuery, true, "OnNewCP", "");
            }
           
            forward OnNewCP();
            public OnNewCP()
            {
                new rows, fields, posx[10], posy[10], posz[10];
                cache_get_data(rows, fields);
                if(rows)
                {
                    cache_get_row(0, 3, posx);
                    cache_get_row(0, 4, posy);
                    cache_get_row(0, 5, posz);
                    SendFormatMessage(-1,RED,"asd: %f,  %f , %f",posx,posy,posz);
                }
            }
Reply
#7

is it not good?
0,0,0 Their position is created


Код:
CREATE TABLE IF NOT EXISTS `cp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `x` float NOT NULL,
  `y` float NOT NULL,
  `z` float NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;
Код:
stock NewCP()
{
format(g_szQuery, sizeof g_szQuery, "SELECT * FROM cp ORDER BY RAND() LIMIT 1;");
                mysql_function_query(1, g_szQuery, true, "OnNewCP", "");
            }
            
            forward OnNewCP();
            public OnNewCP()
            {
                new rows, fields, posx[10], posy[10], posz[10];
                cache_get_data(rows, fields);
                if(rows)
                {
                    cache_get_row(0, 1, posx);
                    cache_get_row(0, 2, posy);
                    cache_get_row(0, 3, posz);
                    SendFormatMessage(-1,RED,"asd: %f,  %f , %f",posx,posy,posz);
                }
            }
Reply
#8

help
Reply
#9

help
Reply
#10

pawn Код:
stock NewCP()
{
    format(g_szQuery, sizeof g_szQuery, "SELECT * FROM cp ORDER BY RAND() LIMIT 1;");
    mysql_function_query(1, g_szQuery, true, "OnNewCP", "");
}

forward OnNewCP();
public OnNewCP()
{
    new
        rows,
        fields,
        fetch[12],
        Float:pos[3];
    cache_get_data(rows, fields);
    if(rows)
    {
        cache_get_row(0, 1, fetch); pos[0] = floatstr(fetch);
        cache_get_row(0, 2, fetch); pos[0] = floatstr(fetch);
        cache_get_row(0, 3, fetch); pos[0] = floatstr(fetch);
        SendFormatMessage(-1, RED, "asd: %f,  %f, %f", pos[0], pos[0], pos[2]);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)