PHP and Mysql Handle Multiple Results
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
PHP and Mysql Handle Multiple Results
Hello community
Ok, i used to use this "function" a lot but now i just forgot it...
It goes like this, im trying to use the runcron to update all the villages.
So i do this (diagram)
Query Players Villages -> Check Number of Results ->
Now i wanna know what function for mysql using a while loop or something i need to use, for update the first result (first village), then the second, then third and even if there are more..
I just forgot.. it was something like: mysql_something($i, "Table ROW", $query);
Anyone knows this?
Thanks
Ok, i used to use this "function" a lot but now i just forgot it...
It goes like this, im trying to use the runcron to update all the villages.
So i do this (diagram)
Query Players Villages -> Check Number of Results ->
Now i wanna know what function for mysql using a while loop or something i need to use, for update the first result (first village), then the second, then third and even if there are more..
I just forgot.. it was something like: mysql_something($i, "Table ROW", $query);
Anyone knows this?
Thanks
Re: PHP and Mysql Handle Multiple Results
You mean mysl_fetch_assoc($result)?
while($row = mysql_fetch_assoc($result)){
// update all the villages
}
while($row = mysql_fetch_assoc($result)){
// update all the villages
}
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: PHP and Mysql Handle Multiple Results
Well i dont think so...
How can i use that one to update more than 1 village in a loop?
Also, is there any manual with all the mysql functions ?
How can i use that one to update more than 1 village in a loop?
Also, is there any manual with all the mysql functions ?
- Sharlenwar
- Posts: 523
- Joined: Mon May 28, 2012 7:14 pm
Re: PHP and Mysql Handle Multiple Results
I'm not too sure what sort of commands you would have in php, but if you have any sort of looping, then you would simply make a loop to iterate through all your villages to update them.
Or is it something else you are after?
Or is it something else you are after?
Deep within the Void of Quasion, a creation.
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
**My Corner of the Web**
***NEW***GrindFest - My own PHP/MySQL game!
Sharlenwar's Adventures
Torn-City - Massively multiplayer online text based RPG
Re: PHP and Mysql Handle Multiple Results
This site might have what you're looking for http://www.w3schools.com/php/php_ref_mysql.asp
Skills: HTML5, JavaScript, PHP, SQL, Python, BASIC, HeroEngine(HSL), AGS(Lua), Unity, Photon, 3D Max, Mudbox, Photoshop, Poser, Flash
"Jack-of-all-Trades, Master of none"
"Jack-of-all-Trades, Master of none"
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: PHP and Mysql Handle Multiple Results
Well, i checked w3schools before post but couldnt find the function..
But hey, if you got any other ideas.
The goal is simple, i got 2 or more things to update.
Like : $query = "SELECT * from villages where owner= $playerid"
So if the player has 2 or more villages.. how can i update each one (getting each field for each village)
But hey, if you got any other ideas.
The goal is simple, i got 2 or more things to update.
Like : $query = "SELECT * from villages where owner= $playerid"
So if the player has 2 or more villages.. how can i update each one (getting each field for each village)
Re: PHP and Mysql Handle Multiple Results
I know people could even do that using only SQL, but since I'm not much of an SQL guy I do it with PHP. Xaleph already posted what you need:
All the PHP documentation can be found at http://php.net/
Here's the mysql docu: http://php.net/mysql
Code: Select all
$userVillagesQuery = mysql_query("SELECT * FROM `villages` WHERE `owner_id` = $playerid");
// loop through each village
while( $village = mysql_fetch_assoc($userVillagesQuery) )
{
// do update
mysql_query("UPDATE `villages` SET `iron` = '" . ($village['iron'] + 5000) . "' WHERE `id` = {$village['id']}");
}
Here's the mysql docu: http://php.net/mysql
Fighting for peace is declaring war on war. If you want peace be peaceful.
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: PHP and Mysql Handle Multiple Results
Ok sorry xaleph i didnt understood how to use the assoc function.
I used now, but got a problem.. i think the while loop is not being completed :S Because in the pages that i got include runcron the content of the page doesnt show...
do i need a $i ++; or smth?
I used now, but got a problem.. i think the while loop is not being completed :S Because in the pages that i got include runcron the content of the page doesnt show...
do i need a $i ++; or smth?
Re: PHP and Mysql Handle Multiple Results
Nope, the while loop takes care of that for you, or actually, mysql_fetch_assoc() does, if nothing is found, false will return, so the while() breaks. If you don`t get any content, then either the query is wrong, or the included runcron() function.
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: PHP and Mysql Handle Multiple Results
well, i got this:
and still no thing is showed.. not even "working"..
Code: Select all
$aldeias = mysql_query("SELECT * from villages where username= '$username'");
$aldeias_result = mysql_fetch_array($villages);
$aldeias_result_number = $mysql_num_rows($villages);
while($village = mysql_fetch_assoc($aldeias))
{
echo "working";
}