Selecting more fields with the same fieldname
#1

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.
Reply
#2

You could try using a for loop.
Reply
#3

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
Reply
#4

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
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)