Values from different table
#1

Код:
mysql_format(handle, _query, sizeof(_query), "SELECT `AdminLevel`, `VIPLevel`, `RP`, `Hour`, `Skin`, `Coins`, `Gender`, `AliveTime` FROM `accounts` WHERE `Username` = '%e'", params);
	results = mysql_query(handle, _query);
	cache_get_value_name_int(0, "AdminLevel", adminLevel);
	cache_get_value_name_int(0, "VIPLevel", vipLevel);
	cache_get_value_name_bool(0, "RP", regularPlayer);
	cache_get_value_name_int(0, "Hour", score);
	cache_get_value_name_int(0, "Skin", skin);
	cache_get_value_name_int(0, "Coins", zCoins);
	cache_get_value_name_int(0, "Gender", gender);
	cache_get_value_name_int(0, "AliveTime", aliveTime);
	cache_delete(results);


	format(_query, sizeof(_query), "00,12--------[%s's stats]--------", params);
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "Admin Level: \x1D%d\x1D", adminLevel);
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "Premium Level: \x1D%d\x1D", vipLevel);
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "Regular player: \x1D%s\x1D", regularPlayer ? "Yes" : "No");
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "Score: \x1D%d\x1D", score);
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "zCoins: \x1D%d\x1D", zCoins);
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "Gender: \x1D%s\x1D", gender == 1 ? ("Male") :  gender == 2 ? ("Female") : ("Not specified"));
	IRC_GroupSay(gGroupID, channel, _query);

	format(_query, sizeof(_query), "Alive time: \x1D%d\x1D minute(s)", aliveTime / 60);
	IRC_GroupSay(gGroupID, channel, _query);
	
	IRC_GroupSay(gGroupID, channel, "00,12------------------------------");
I updated the database so they are not just in a single table.

Like; on table "accounts" u can see the "AdminLevel,VIPLevel,RP" but on another table called "Stats" where u can see "Hour,SKin,Coins,Gender,Alivetime"...

How can I select from 2 different tables? Thanks.
Reply
#2

Hello?
Reply
#3

You need relation between two tables in order to fetch data from both.Otherwise it will produce cartesian product between two tables as in SETS.
PHP код:
SELECT value_in_table1,value_in_table2
 FROM table1
,table2
WHERE table1
.commonid table2.commonid 
The above query performs an equi-join on two tables table1 and table2 and commonid is the field which has matching value in table1 and table2.
You can refer more about JOINS here
https://en.wikipedia.org/wiki/Join_%28SQL%29
https://www.w3schools.com/sql/sql_join.asp
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)