mysql_format into variable.
#1

Hi, I'm tryna make a new house system. so, here's my question.

I'm tryna get a minimum of id and maximum of id from the house table.

So, I made two variables for minimum and maximum. and, is it possible to put the mysql_format into the variables? If yes, could you give me some examples?
Reply
#2

http://stackoverflow.com/questions/1...as-a-min-value

Does this seem relevant? I'm sure there is a max value to tag with it.

Not sure about putting mysql_format into the variables, didn't really understand
Reply
#3

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
http://stackoverflow.com/questions/1...as-a-min-value

Does this seem relevant? I'm sure there is a max value to tag with it.

Not sure about putting mysql_format into the variables, didn't really understand
Thanks, anyway.

I meant.. like..
Код:
new min = mysql_format(blah.. blah.., "SELECT...");
can i put the mysql_format into variable like that? sorry for my english.
Reply
#4

Nah, you need to fetch the values through the callback by the looks. That function appears to only be a function that formats a query into a string.

pawn Код:
new query[128];
mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
// the variable 'query' contains now the formatted query (including the escaped string)
mysql_tquery(MySQL, query, "OnStuffSelected", "");
taken from https://sampwiki.blast.hk/wiki/MySQL/R33

Therefore, it should look similar to this (untested, might work tho):

pawn Код:
// query somewhere
mysql_tquery(MySQL, "SELECT MIN(`column`) as `min_val` FROM `table`", "OnStuffSelected", "");

// callback
public OnStuffSelected()
{
    new
        rows, fields;

    cache_get_data(rows, fields);

    if(rows) {
        new minval = cache_get_row_int(0, "min_val"); // 0 = first row
        // do stuff
    }
}
Reply
#5

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
Nah, you need to fetch the values through the callback by the looks. That function appears to only be a function that formats a query into a string.

pawn Код:
new query[128];
mysql_format(MySQL, query, sizeof(query), "SELECT * FROM `%s` WHERE `bar` = '%e' AND `foobar` = '%f' LIMIT %d", "foobar", "escape'me\"please", 1.2345, 1337);
// the variable 'query' contains now the formatted query (including the escaped string)
mysql_tquery(MySQL, query, "OnStuffSelected", "");
taken from https://sampwiki.blast.hk/wiki/MySQL/R33

Therefore, it should look similar to this (untested, might work tho):

pawn Код:
// query somewhere
mysql_tquery(MySQL, "SELECT MIN(`column`) as `min_val` FROM `table`", "OnStuffSelected", "");

// callback
public OnStuffSelected()
{
    new
        rows, fields;

    cache_get_data(rows, fields);

    if(rows) {
        new minval = cache_get_row_int(0, "min_val"); // 0 = first row
        // do stuff
    }
}
Thanks, I was always wondering about that. thanks for helping me out.

Also, could I two mysql_format and tquery like this?

pawn Код:
stock LoadHouses()
{
    new query[120];
   
    mysql_format(g_Handle, query, sizeof(query), "SELECT * FROM `houses`");
    mysql_tquery(g_Handle, query, "OnLoadHouses", "");
    return 1;
}

public OnLoadHouses()
{

        mysql_tquery(MySQL, "SELECT MIN(`column`) as `min_val` FROM `table`", "OnStuffSelected", "");

    for(new i = 0; i < cache_get_row_count(); i++)
    {
        g_HouseInfo[i][house_ID]            = cache_get_field_content_int(i, "H_ID");
            blahh....
        }
}

public OnStuffSelected()
{
    new
        rows, fields;

    cache_get_data(rows, fields);

    if(rows) {
        new minval = cache_get_row_int(0, "min_val"); // 0 = first row
        // do stuff
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)