Little help needed - mysql
#1

hello guys.

I was creating one system and I have the following things at mysql
Код:
id 
name
text
Now, im selecting these like this:

Код:
format(Query, sizeof(g_Query), "SELECT * FROM police");
		mysql_query(Query);
Now I want such kind thing that if I do /search NAME - if the NAME is in the police database > name then it will show the text. If that NAME is not in the databse then it will not show.

Simply:

/search NAME -> If in database is this name then it will show TEXT that it is in database.

Helpp
Reply
#2

Help neeeded! +1 REP !!

Simpy that it checks DB and this name I searched.
Reply
#3

Use mysql_num_rows() to check if a row exists using a query like so:

"SELECT * FROM `tablename` WHERE Name = '%s (player's name)'"
Reply
#4

Код:
new
			dName = strval(inputtext),
			g_Query[ 1000 ]
		;
			
        format(g_Query, sizeof(g_Query), "SELECT * FROM police WHERE kname = '%s'", dName);
		mysql_query(g_Query);
		if(mysql_num_rows() > 0)
  		{
			SendClientMessage(playerid, -1, "Name is.");
			return 1;
		}
Doesnt work.. I did something wrong.
Reply
#5

pawn Код:
format(g_Query, sizeof(g_Query), "SELECT * FROM police WHERE name = '%s'", inputtext);
        mysql_query(g_Query);
        new result = mysql_num_rows();
        if(result)
        {
            SendClientMessage(playerid, -1, "Name is.");
            return 1;
        }
Reply
#6

Whatever name I write, it says Name is.
What's wrong.. ?
Reply
#7

pawn Код:
format(g_Query, sizeof(g_Query), "SELECT * FROM police WHERE name = '%s'", inputtext);
    mysql_query(g_Query);
    mysql_store_result();
        new result = mysql_num_rows();
    if(result)
    {
        new Storage[128];
        if(mysql_retrieve_row()) {
            mysql_fetch_field_row(Storage, "text");
        }
        format(g_Query, sizeof(g_Query), "Text is: %s", Storage);
        SendClientMessage(playerid, -1, g_Query);
    } else {
        SendClientMessage(playerid, -1, "Name isn't");
    }
    mysql_free_result();
    return 1;
Reply
#8

After executing a select query, you must ALWAYS first use mysql_store_result, even before calling mysql_num_rows, otherwise you'll get problems.
Edit: 2000th post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)