SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/08/2017, 05:33 AM   #1
KizZweLL
Little Clucker
 
KizZweLL's Avatar
 
Join Date: Jan 2016
Location: Philippines
Posts: 24
Reputation: 0
Default Mysql Fetching Row

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

PHP Code:
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;

__________________
Sometimes impossible can turn into reality.
KizZweLL is offline   Reply With Quote
Old 13/08/2017, 05:41 AM   #2
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Location: Los Angeles
Posts: 681
Reputation: 93
Default Re: Mysql Fetching Row

What's the point of storing a player's position in a separate table from accounts?
Arthur Kane is offline   Reply With Quote
Old 13/08/2017, 05:43 AM   #3
KizZweLL
Little Clucker
 
KizZweLL's Avatar
 
Join Date: Jan 2016
Location: Philippines
Posts: 24
Reputation: 0
Default Re: Mysql Fetching Row

The point is just simple.
To make your table looks more clear
__________________
Sometimes impossible can turn into reality.
KizZweLL is offline   Reply With Quote
Old 13/08/2017, 06:21 AM   #4
KizZweLL
Little Clucker
 
KizZweLL's Avatar
 
Join Date: Jan 2016
Location: Philippines
Posts: 24
Reputation: 0
Default Re: Mysql Fetching Row

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
__________________
Sometimes impossible can turn into reality.
KizZweLL is offline   Reply With Quote
Old 13/08/2017, 06:27 AM   #5
Storm94
Little Clucker
 
Join Date: Dec 2012
Posts: 26
Reputation: 0
Default Re: Mysql Fetching Row

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.
__________________
USA Trucking! - http://usa-trucking.net
play.usa-trucking.net:7777
[Insert Banner Here (I don't have one yet )]
----
Stop the abuse of the "stock" keyword! http://forum.sa-mp.com/showthread.php?t=570635
Storm94 is offline   Reply With Quote
Old 13/08/2017, 08:00 AM   #6
KizZweLL
Little Clucker
 
KizZweLL's Avatar
 
Join Date: Jan 2016
Location: Philippines
Posts: 24
Reputation: 0
Default Re: Mysql Fetching Row

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.
__________________
Sometimes impossible can turn into reality.
KizZweLL is offline   Reply With Quote
Old 13/08/2017, 08:17 AM   #7
X337
Gangsta
 
X337's Avatar
 
Join Date: Sep 2014
Location: Indonesia
Posts: 855
Reputation: 213
Default Re: Mysql Fetching Row

Quote:
Originally Posted by KizZweLL View Post
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.
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Old 13/08/2017, 08:29 AM   #8
KizZweLL
Little Clucker
 
KizZweLL's Avatar
 
Join Date: Jan 2016
Location: Philippines
Posts: 24
Reputation: 0
Default Re: Mysql Fetching Row

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.
__________________
Sometimes impossible can turn into reality.
KizZweLL is offline   Reply With Quote
Old 13/08/2017, 09:04 AM   #9
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 11,045
Reputation: 2647
Default Re: Mysql Fetching Row

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.
__________________
Vince is offline   Reply With Quote
Old 13/08/2017, 09:13 AM   #10
KizZweLL
Little Clucker
 
KizZweLL's Avatar
 
Join Date: Jan 2016
Location: Philippines
Posts: 24
Reputation: 0
Default Re: Mysql Fetching Row

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.
__________________
Sometimes impossible can turn into reality.
KizZweLL is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL fetching a boolean value dominik523 Scripting Help 3 25/01/2015 11:05 AM
MySQL not fetching. EliteApple Scripting Help 2 22/09/2013 02:02 AM
[MySQL] Not fetching all groups [TC]XxJuggaloxX Scripting Help 2 26/02/2013 12:52 AM
Fetching vehicle MySQL ID from SAMP ID zDevon Scripting Help 3 07/01/2013 02:01 AM
mySQL fetching PDChaseOfficial Scripting Help 0 04/01/2013 04:53 PM


All times are GMT. The time now is 02:45 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.