Mysql not updating a row.
#1

Im working on loading clubs. When it loads the clubs it searches in the user database to all the people who have the name of the club in their profile. If they do they get selected and in the OnMembersUpdate(CName) the rows should be counted and a query should be send to the Clubs table to update Members column.
Now first of all the rows i want to count generate a weird number. I have only 1 club with only 1 profile that should be attached to it. But the printf prints 8712 and the query does nothing at all.
This is the code:
pawn Код:
forward OnMembersUpdate(CName);
public OnMembersUpdate(CName)
{
    new rows, fields, string[128];
    cache_get_data(rows, fields, Handle);
    if(!rows)
    {
        printf("No results");
        return 1;
    }
    else
    {
        format(string, sizeof(string), "UPDATE Clubs SET Members = '%d' WHERE Name = '%s'", rows, CName);
        printf("%i", rows);
        mysql_function_query(Handle, string, true, "", "");
    }
    return 1;
}
Does anyone see the problem?

Edit: Weird enough CName seems to be empty already in the LoadClubs part. i've got this over there:
pawn Код:
forward LoadClubs();
public LoadClubs()
{
    new rows, fields, i = 0;
    cache_get_data( rows, fields, Handle);
    if(!rows)
    {
        print("Clubs table is empty, no results found.");
        return 1;
    }
    while(rows > i < MAX_CLUBS)
    {
        new string[128];
        AClubData[i][ID] = cache_get_row_int(i, 0, Handle);
        cache_get_row(i, 1, AClubData[i][Owner], Handle, 1);
        AClubData[i][ClubX] = cache_get_row_float(i, 2, Handle);
        AClubData[i][ClubY] = cache_get_row_float(i, 3, Handle);
        AClubData[i][ClubZ] = cache_get_row_float(i, 4, Handle);
        cache_get_row(i, 5, AClubData[i][ClubName], Handle);
        printf("%s", AClubData[i][ClubName]);
        AClubData[i][ClubMembers] = cache_get_row_int(i, 21, Handle);
        format(string, sizeof(string), "SELECT Club FROM Users WHERE Club = '%s'", AClubData[i][ClubName]);
        mysql_function_query(Handle, string, true, "OnMembersUpdate", "s", AClubData[i][ClubName]);
        AClubData[i][PickUpID] = CreateDynamicPickup(1210, 1, AClubData[i][ClubX], AClubData[i][ClubY], AClubData[i][ClubZ], -1);
        printf("Club %d Loaded", i);
        i++;
    }
    return 1;
}
i've printed the ClubName to console. it prints out an empty line. Why does it do this?
Also the club name in database is not empty:
http://gyazo.com/2e6758b18f147b20b6007f487d9ea2d5
Reply
#2

You shouldn't need to save the number of members at all since MySQL has perfectly good counting functions.

PHP код:
SELECT ClubCOUNT(*) AS Members FROM Users GROUP BY Club 
That should give a list of all clubs and the number of members. Alternatively, to filter a single one you can add a HAVING clause;

PHP код:
SELECT ClubCOUNT(*) AS Members FROM Users GROUP BY Club HAVING Club '%s' 
Reply
#3

You mean like this?:
pawn Код:
format(string, sizeof(string), "SELECT Club, COUNT(*) AS Members FROM Users GROUP BY Club HAVING Club = '%s''", AClubData[i][ClubName]);
Edit: i did that. it only works with 1 profile. I added another 1 and it still says 1.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)