SQL question
#1

Okay I am not what you can say a pro at MySQL, so I need a little help.
How to get info from a database?
I thaught it was:
Код:
new query;
format(query, sizeof(query), SELECT MYSQLSTUFFHERE,NAME, IP);
mysql_query(query);
I need to select like 6 strings from 1 table and use them.
Reply
#2

SELECT 'info' FROM 'table' WHERE 'something'='%s'

Example:

pawn Код:
new playername[MAX_PLAYER_NAME], query[100];
GetPlayerName(playername, sizeof(playername));
format(query, sizeof(query), "SELECT * FROM 'users' WHERE 'username'='%s'", playername); // Will select all the info of a user
mysql_query(query);
Reply
#3

Good help @ Wiki
https://sampwiki.blast.hk/wiki/MySQL#mysql_query <<- Thats what u need
https://sampwiki.blast.hk/wiki/MySQL <<- Usefull information in future
Reply
#4

there you go:

pawn Код:
new query[128], ip, ip2, name, pname[MAX_PLAYER_NAME];
name = GetPlayerName(playerid, pname, sizeof(pname));
ip = GetPlayerIp(playerid, ip2, sizeof(ip2));
format(query, sizeof(query),"SELECT * FROM yourtable WHERE name = '%s' AND ip = '%f'", name, ip);
mysql_query(query);
it must be between "" and if you want to select all info from the table use *, * = all.

basicly function will: select all info from your table where your ip and name match the tableґs fields name and ip, since there will be other names and ips.
Reply
#5

Quote:
Originally Posted by Steeve_Smith
Посмотреть сообщение
SELECT 'info' FROM 'table' WHERE 'something'='%s'

Example:

pawn Код:
new playername[MAX_PLAYER_NAME], query[100];
GetPlayerName(playername, sizeof(playername));
format(query, sizeof(query), "SELECT * FROM 'users' WHERE 'username'='%s'", playername); // Will select all the info of a user
mysql_query(query);
Does it list the row that is exactly the value entered?
And how to use it with format exactly because I have multiple values.
Reply
#6

Quote:
Originally Posted by Jeroen52
Посмотреть сообщение
Does it list the row that is exactly the value entered?
And how to use it with format exactly because I have multiple values.
'*' returns all of your table where the username of the user = the username that you put in %s. If you need a special info, just do 'SELECT 'theinfo' FROM 'table' WHERE 'username'='%s'

What do you exactly need in your query?
Reply
#7

Well I have something like this, ofcourse it is different.
How can I select Jeroen?

NAME | IP | CASH | JAILTIME | SCORE | WEED
__________________________________________________ ____________
JEROEN | 192.168.43.41 | 4414125 | 514 | 4141 | 41
__________________________________________________ ____________
PLAYER | 192.168.43.42 | 6448195 | 111 | 2052 | 18
__________________________________________________ ____________
NOOB | 120.200.40.31 | 44125 | 5000 | 1 | 0
__________________________________________________ ____________
Reply
#8

SELECT name, ip, jailtime, score, weed FROM 'yourtable' WHERE 'username'='%s'
Reply
#9

Quote:
Originally Posted by Steeve_Smith
Посмотреть сообщение
SELECT name, ip, jailtime, score, weed FROM 'yourtable' WHERE 'username'='%s'
Thank-you I will try that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)