Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Eudemons Online > EO PServer Hosting
You last visited: Today at 00:34

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[help] mysql data loop betwean differend tables

Discussion on [help] mysql data loop betwean differend tables within the EO PServer Hosting forum part of the Eudemons Online category.

Reply
 
Old   #1

 
PowerChaos's Avatar
 
elite*gold: 90
Join Date: Feb 2008
Posts: 1,112
Received Thanks: 642
[help] mysql data loop betwean differend tables

hi all
i was wondering if some1 know why this is refusing to work

Code:
$charshout = mysql_query("SELECT * FROM cq_user WHERE (`account_id` LIKE '".$_SESSION['id']."' )");
while ($user = mysql_fetch_assoc($charshout))
{
$i = $i+1;
$shoutpersonal[$i] = mysql_query("SELECT * FROM cq_ad_log WHERE (`user_name` LIKE '".$user['name']."') ORDER BY publish_time ASC LIMIT 5");
}

while($shouting = mysql_fetch_array($shoutpersonal[$i]))
{
the thing i try to do is to show all shouts from the characters

so the db need to do a loop to get all characters and then show the amount of characters

the data get taken from 2 tables , first you have account id that start searching for the character id ( as account_id == Character , and character_id == shouts )

so first i need to get the character id , and need to loop that until it got all characters

then it need to loop to show the shouts of all characters , limiting to 5 shouts and show the character name

so far it is partial working , for 1 of other reason the loop is not working like it need to be
it only shows the second character or no data if there is no second character

i was wondering if some1 could provide me a working code for that

if more code is needed for the example , feel free to ask and i shal release the full code of the page i am trying to get working

if there is no code/solution for this , then i just change the way the data get displayed (with a form , always works )

Greetings From PowerChaos
PowerChaos is offline  
Old 01/29/2012, 08:58   #2
 
funhacker's Avatar
 
elite*gold: 20
Join Date: Sep 2007
Posts: 1,767
Received Thanks: 1,746
For starters I would only select the cq_user.id or both cq_user.id and cq_user.name, selecting all the data is pointless.

Now as I don't have navicat installed at the moment I couldn't go right into the cq_ad_log
But then I would create an array of strings using the following

select message from cq_ad_log where user_id == user_id;

Note that message is the field that ad log uses to save the actual broadcast message. Then user_id is the "external" key.

External Key:
Is a relationship between 2 tables, it most commonly is a one to many relationship which means in one table it will only have 1 occurrence (cq_user.id) and in another table it will have many occurrences (cq_ad_log.user_id).
The external key may be the user's name but as that's not the cq_user primary key it would be poor database design. So I'm assuming that they also have user id present in the ad log.

Then once you have the string array you could simply loop through the array's length like so

for (int messIndex = 0; messIndex < array.Length; messIndex++)
{
.....
}


This is all purely pseudo code as I know absolutely no php at this time. Also a tip, when you have a fixed length object that you would get from an array of answers, correct coding suggests you use a for loop.
Whiles are used for unknown lengths, like reading a text file line by line.
funhacker is offline  
Thanks
1 User
Old 01/29/2012, 15:40   #3

 
PowerChaos's Avatar
 
elite*gold: 90
Join Date: Feb 2008
Posts: 1,112
Received Thanks: 642
Thank you funhacker

only problem with cq_ad_log is that it got only 3 rows
cq_ad_log.name
cq_ad_log.message
cq_ad_log_date (no timestamp , normal date )

and name is indeed the primary key (bad coded)
i am not sure , but it should be possible that date is the unic key value (every min limit ?)

if date is the unic key then its a realy big problem as there is no way to find it back on date (as that is not a matched key betwean tables)

so i get something as those value's below

PHP Code:
$sesiion[id] = account.id after login (get stored as a sesion)
account.id primary
cq_user
.id  =  primary
cq_user
.account_id primary id from account.id
cq_user
.name primary for cq_ad_log.name
cq_ad_log
.name primary 
because of that bad code do i need to get the name that match the id , as everything is working over a id in the other tables

the array is not realy possible to , as i cap the messages at 5 rows , but it need to match the names and it is not a unic value in cq_ad_log but a unic value in cq_users

so basicly if you got 5 differend characters then it need to loop until it got all 5 differend characters and show the top 5 from all 5 characters (cq_users.account_id )

if character 1 got 5 shouts and character 2 got 3 shouts , then it should show only the 5 latest shouts of both characters

2 latest messages is from char1 , when 3 latest messages is from char2 = 5 shouts from 2 differend chars showing under each other sorted on date

in meantime i fixed it with following code

PHP Code:
while ($charlist mysql_fetch_assoc($chardata))
{
echo 
"<option value ='".$charlist['id']."'>".$charlist[name]."</option>";
}
?>
</select>
</table>
<br>
<input class=Butt type=submit value="See Character Stats" name="search">
</FORM> 
and then based on id it get the name and stuff

but i still wonder why the below code works perfect in a loop when for the characters it doesnt :S
PHP Code:
while ($petinfo mysql_fetch_assoc($petdata))
{
$petnames mysql_query("SELECT * FROM cq_table WHERE (`id` LIKE '".$petinfo['table']."' )");
$petname mysql_fetch_assoc($petnames);
echo (
"<td>".$petname['table']."</td>");

it exact does what it need to do , it select the id from table X and then keeps looping and showing all names that match the eudemons primary key
and then it just shows the pets there name and it works perfect (its a 2 table hop , edited above code to provide example )

ayway , thank you for your solution and i am sure i can use it for other purposes now i got a idea how to make a loop on a differend way then using While

ps: it is still hard to make a control panel :P

Thank you
Greetings From PowerChaos
PowerChaos is offline  
Reply


Similar Threads Similar Threads
MYsql Data Exception.
08/30/2011 - CO2 Private Server - 7 Replies
Hello, i got little bug in my server that do that and We can't log in, Major lag in game :S http://s3.noelshack.com/uploads/images/1006543257 6078_screen2.jpg http://s3.noelshack.com/uploads/images/2020682921 499_screen_1.jpg I pray my screen will help to understand.
Tables only read MySql Problem
10/28/2010 - Metin2 Private Server - 3 Replies
Joooo, Quote: Table 'player.item_proto' is read only Egal was ich da mach, die Fehlermeldung kommt 1x Alle Tables rausgenommen sql Backup eingespielt: Table 'player.item_proto' is read only Alles raus Myi/Myd Backup eingespielt: Table 'player.item_proto' is read only Alles raus, cleane Db, von Profifighter eingespielt:
Could not locate the assembally "MySql.Data"
07/29/2009 - CO2 Private Server - 2 Replies
I have this error in Visual C#... I've tried overwriting the MySql.Data.dll with the defualt one several times. I havnt edited the file either but suddenly it wont work and its telling me MySqlCommand, MySqlDataAdapter & MySqlConnection are all failing :l. Help... Please?
My Cq Data at zfserver\MYSQL\data
01/14/2009 - CO2 Private Server - 3 Replies
sorry
Agbot loop dosnt loop
10/18/2008 - Silkroad Online - 1 Replies
my agbot after i tele will go through the 20 sec wait then says in bot concle feature not available yet feature not available yet idk whats wrong



All times are GMT +1. The time now is 00:34.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.