View Contact | MySQL Not Loopp
#1

What this code is supposed to do is display contacts that the player has added via the MySQL. Everytime the player inserts the contact it goes into the MySQL but when the player tries to view the contacts they've added, it will only display 1 contact. So it's looping through 1 result. I've tried debugging it and made it print values and it's printing the correct values but it's not looping through everything. You can see the values it prints in the image below.

Here is the image: http://i.imgur.com/jUXNu.png

Код:
					case 1:
					{
						new string[128], data[100], contact[MAX_PLAYER_NAME], person[MAX_PLAYER_NAME], number, shit[1024];print("1");
						c_NextSelection[playerid] = 0;print("2");
						format(string, sizeof(string), "SELECT * FROM `contacts` WHERE `player` = '%s'", pNameEx(playerid));print("3");
						mysql_query(string);print("4");
						mysql_store_result();print("5");
						//format(string, sizeof(string), "");print("6");
						printf("rows: %d", mysql_num_rows());
						
						if(mysql_num_rows() > 1)
						{
							while(mysql_retrieve_row())
							{
								print("7");
								mysql_fetch_row(data);printf("data: %s", data);print("8");
								sscanf(data, "p<|>s[24]s[24]d", person, contact, number);print("9");
								c_Selections[playerid][c_NextSelection[playerid]] = number;print("10");
								c_NextSelection[playerid]++;print("11");
								format(shit, sizeof(shit), "%s%s\n", shit, stringUnderscore(contact));printf("ct-ori: %s, func: %s", contact, stringUnderscore(contact));print("12");
								print(shit);
								print("13");
							}
							print("14");
							ShowPlayerDialog(playerid, DIALOG_CONTACTS3, DIALOG_STYLE_LIST, "Contacts", shit, "Select", "Back");print("15");
							print(shit);
						}
						else
						{
							print("7-ex");
							mysql_fetch_row(data);printf("data: %s", data);print("8");
							sscanf(data, "p<|>s[24]s[24]d", person, contact, number);print("9");
							c_Selections[playerid][c_NextSelection[playerid]] = number;print("10");
							c_NextSelection[playerid]++;print("11");
							format(string, sizeof(string), "%s%s\n", string, stringUnderscore(contact));printf("ct-ori: %s, func: %s", contact, stringUnderscore(contact));print("12");
							print(string);
							print("13");
							ShowPlayerDialog(playerid, DIALOG_CONTACTS3, DIALOG_STYLE_LIST, "Contacts", string, "Select", "Back");print("15");
							print(string);
						}
					}
Any help would be greatly appreciated!
Reply
#2

Does anyone have any idea on how to fix this problem I'm having?
Reply
#3

Like I already said in another topic, either use mysql_retrieve_row or mysql_fetch_row, but not both at the same time. Both functions advance the row pointer so you'll end up with one row skipped, one row loaded, one row skipped, ...

pawn Код:
while(mysql_fetch_row(data))
{
    // sscanf( ... )
}
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Like I already said in another topic, either use mysql_retrieve_row or mysql_fetch_row, but not both at the same time. Both functions advance the row pointer so you'll end up with one row skipped, one row loaded, one row skipped, ...

pawn Код:
while(mysql_fetch_row(data))
{
    // sscanf( ... )
}
Thanks you helped me fix my issue. +REP, though I don't think it'll help much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)