Mysql Fetching Row
#1

Hello, I've made this thread to ask a question if it is allowed to fetch a row twice in a different table?

PHP код:
stock LoadPosition(playerid)
{
    new 
query[100],aName[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,aName,sizeof(aName));
    
format(query,sizeof(query),"SELECT * FROM positions WHERE Name = '%s'",aName);
    while(
mysql_fetch_row_format(query,"]["))
    {
        
mysql_fetch_field_row(query,"PositionX");     PlayerPos[playerid][Pos][0] = floatstr(query);
        
mysql_fetch_field_row(query,"PositionY");     PlayerPos[playerid][Pos][1] = floatstr(query);
        
mysql_fetch_field_row(query,"PositionZ");     PlayerPos[playerid][Pos][2] = floatstr(query);
        
mysql_fetch_field_row(query,"Angle");        PlayerPos[playerid][Angle] = floatstr(query);
    }
    
SetSpawnInfo(playerid,0,0,PlayerPos[playerid][Pos][0],PlayerPos[playerid][Pos][1],PlayerPos[playerid][Pos][2],PlayerPos[playerid][Angle],0,0,0,0,0,0);
    
SetCameraBehindPlayer(playerid);
    
SpawnPlayer(playerid);
    
    return 
1;
}
stock LoginPlayer(playerid)
{
    new 
query[100],aName[MAX_PLAYER_NAME];
    
GetPlayerName(playerid,aName,sizeof(aName));
    
format(query,sizeof(query),"SELECT * FROM accounts WHERE Name = '%s'",aName);
    while(
mysql_fetch_row_format(query,"]["))
    {
        
mysql_fetch_field_row(query,"Cash"); PlayerInfo[playerid][Cash] = strval(query);
        
mysql_fetch_field_row(query,"Kills"); PlayerInfo[playerid][Kills] = strval(query);
    }
    
GivePlayerMoney(playerid,PlayerInfo[playerid][Cash]);
    
PlayerPlaySound(playerid,1057,2,2,3);
    return 
1;

Reply
#2

What's the point of storing a player's position in a separate table from accounts?
Reply
#3

The point is just simple.
To make your table looks more clear
Reply
#4

Seems this problem is being ignored.
Sorry for bumping but I need to fix this rightaway.

The question again is.
Is it possible to Fetch a Row at the same time in different tables?
if yes. please explain how am I going to fix it.

Thanks
Reply
#5

Not exactly sure what you mean by "fetch a row at the same time in different tables".

Something like a JOIN? You may want to look up SQL JOINs, it sounds like what you are trying to accomplish.
Reply
#6

What I mean is.

When you Fetch a row from table accounts, It doesn't Fetch a row from positions table.
It only gets values from accounts table not in positions. Even though I use a different query on both sides.

but it do return correctly the main problem is it is not getting value to a certain Row.
Reply
#7

Quote:
Originally Posted by KizZweLL
Посмотреть сообщение
The point is just simple.
To make your table looks more clear
If your point by separating coordinate's columns into another table is just to make your table looks more clear, you are wrong. Clear or not the output is, is depends on your query. It's faster and easier for you if you put those columns in one table with the others player's data.
Reply
#8

How about how to use Fetch_Row_Format in different filterscript?
you can only Fetch a Row from a single script when you do it twice the other Row will not be fetched.
Reply
#9

I still don't understand what you're asking. Unless there are multiple positions for individual players (i.e. multiple rows for the same player) there isn't really a need to have those columns in a separate table.
Reply
#10

Just make a tutorial on how to get values from a different tables.

Cite for example.
I am getting a row value from Table called accounts.
and also getting a row value from a table called positions.

The debug only gives me a number of Fetched row from a accounts table not including the positions table.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)