Join the forums now, and start posting to receive access to our Scripts Vault!
$res77 = mysql_query("SELECT * FROM fighters WHERE tourny = '$tourny[id]'"); while($home=mysql_fetch_array($res77)){$res88 = mysql_query("SELECT * FROM fighters WHERE tourny = '$tourny[id]' AND id != '$home[id]'"); while($away=mysql_fetch_array($res88)){ do{ srand ((double) microtime( )*1000000);$fight_day = rand(1,$t_length); srand ((double) microtime( )*1000000);$fight_time = rand(1,4); $resu = mysql_query("SELECT * FROM fights WHERE home_id='$home[id]' AND fight_day='$fight_day' AND fight_time='$fight_time'");$numba = mysql_num_rows($resu);$resu1 = mysql_query("SELECT * FROM fights WHERE away_id='$home[id]' AND fight_day='$fight_day' AND fight_time='$fight_time'");$numba1 = mysql_num_rows($resu1);$resu2 = mysql_query("SELECT * FROM fights WHERE home_id='$away[id]' AND fight_day='$fight_day' AND fight_time='$fight_time'");$numba2 = mysql_num_rows($resu2);$resu3 = mysql_query("SELECT * FROM fights WHERE away_id='$away[id]' AND fight_day='$fight_day' AND game_time='$fight_time'");$numba3 = mysql_num_rows($resu3);$resu4 = mysql_query("SELECT * FROM fights WHERE fight_day='$fight_day' AND t_id='$tourny[id]'");$numba4 = mysql_num_rows($resu4); } while($numba >= "1" && $numba1 >= "1" && $numba2 >= "1" && $numba3 >= "1" && $numba4 >= "4");mysql_query("insert into fights (id, tourny_id, fight_day, home_id, away_id, fight_time) values('', '$tourny[id]', '$fight_day', '$home[id]', '$away[id]', '$fight_time')"); } }
SELECT * FROM fights WHERE fight_day=1 && fight_time=1 && (home_id=1 || away_id=2);
So my question is: does the database insertion happen while the loop is going or after the page is loaded.
Thanks for the input guys. Im just curious though, why does it matter if I prefer to code like that? I kind of self taught myself php just looking at other source code. So by no means am trying to say my method is better or anything. I just would like to know the downsides of having 4 query's as opossed to 1 or 2? Am I actually putting that much more strain on the database in the big picture? Like, would this even be noticed?
I do realize yeah, it is probably the best route to try and optimize your code as best you can, try to use as little code as possible, etc, etc.
Basicly what I would like to know is if I do keep coding like this (really, no optimization in mind), will my game be noticably slower?
Quote from: Dougie on September 30, 2010, 12:00:22 PMI do realize yeah, it is probably the best route to try and optimize your code as best you can, try to use as little code as possible, etc, etc.The amount of code isn't really a big issue. Clarity>Brevity (of course sometimes brevity adds clarity).
Thanks for the input guys. Im just curious though, why does it matter if I prefer to code like that?
I kind of self taught myself php just looking at other source code. So by no means am trying to say my method is better or anything.
I just would like to know the downsides of having 4 query's as opossed to 1 or 2? Am I actually putting that much more strain on the database in the big picture? Like, would this even be noticed?
Quote from: Winawer on September 30, 2010, 12:40:44 PMQuote from: Dougie on September 30, 2010, 12:00:22 PMI do realize yeah, it is probably the best route to try and optimize your code as best you can, try to use as little code as possible, etc, etc.The amount of code isn't really a big issue. Clarity>Brevity (of course sometimes brevity adds clarity).Yup, I definitely agree. The issue in this case is that the code is not clear.