SA-MP Forums Archive
Selecting more fields with the same fieldname - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Selecting more fields with the same fieldname (/showthread.php?tid=258056)



Selecting more fields with the same fieldname - Biesmen - 28.05.2011

I'm not a MYSQL Expert in this stuff: How to select multiple fields, with the same fieldnames. I'd like to find a specific field if I'm using the "WHERE" statement, but then from everyone in the database.
Example: There are two users in the database who have a field: "special" with the same value: 1. I'd like to select those users via MYSQL:
pawn Код:
mysql_query("SELECT `username` FROM `users` WHERE `special` = 1");
This will only detect one username, but I'd like it to select all the usernames in the database who has special with the value 1.

I hope you understand what I mean.


Re: Selecting more fields with the same fieldname - SchurmanCQC - 28.05.2011

You could try using a for loop.


Re: Selecting more fields with the same fieldname - Fj0rtizFredde - 28.05.2011

You could also use * to select eveything.. If that is what you mean?
pawn Код:
mysql_query("SELECT * FROM `users` WHERE `special` = 1");
This will get everyone that has "special" set to 1


Re: Selecting more fields with the same fieldname - Biesmen - 28.05.2011

Quote:
Originally Posted by Fj0rtizFredde
Посмотреть сообщение
You could also use * to select eveything.. If that is what you mean?
pawn Код:
mysql_query("SELECT * FROM `users` WHERE `special` = 1");
No, it won't. I want it to select everyone's username who has "special" as 1. Even with those "ghost" functions in SSCANF it won't work


Re: Selecting more fields with the same fieldname - Vince - 28.05.2011

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
I'm not a MYSQL Expert in this stuff: How to select multiple fields, with the same fieldnames. I'd like to find a specific field if I'm using the "WHERE" statement, but then from everyone in the database.
Example: There are two users in the database who have a field: "special" with the same value: 1. I'd like to select those users via MYSQL:
pawn Код:
mysql_query("SELECT `username` FROM `users` WHERE `special` = 1");
This will only detect one username, but I'd like it to select all the usernames in the database who has special with the value 1.

I hope you understand what I mean.
Did you even test that? Because I'm sure that would work as-is. In your code you just need to use a while loop to mysql_fetch_row each row separately.


Re: Selecting more fields with the same fieldname - Haydz - 28.05.2011

something like this should work.
pawn Код:
new rQuery[60],rName[MAX_PLAYER_NAME];
format(rQuery, sizeof(rQuery), "SELECT `username` FROM `users` WHERE `special = 1");
mysql_query(rQuery);
mysql_store_result( );
while(mysql_fetch_row(rQuery))
{
    sscanf(rQuery, "s[24]", rName);
    //then youc an use rName to display the players names.
}
when you use 'while' it will do the code you put as it finds the matches on the db.


Re: Selecting more fields with the same fieldname - Biesmen - 29.05.2011

Quote:
Originally Posted by Vince
Посмотреть сообщение
Did you even test that? Because I'm sure that would work as-is. In your code you just need to use a while loop to mysql_fetch_row each row separately.
Ah yeah, you're totally right. Well, as I said, I'm not a MYSQL expert, so I didn't think of using a while-loop. Thank you, it's working now.