"; > } > $test_area_query = mysql_query("SELECT * FROM ad_areas > WHERE x = '$start_x' && y = '$start_y'", $my->connection); > if($test_area = mysql_fetch_array($test_area_query)){ > $bg_color = "bgcolor='green'"; > if(($start_x == $cur_spot[0]) && ($start_y == > $cur_spot[1])) > $map_display .= ""; > elseif(($start_x == ($cur_spot[0] - 1)) && ($start_y > == $cur_spot[1]) && (($area[west] != "0") && ($area[west] != > "")) && (($area[w_level] <= $user[level]) OR ($area[w_level] > == $user[clan])) && ($movement != "no")) > $map_display .= ""; > elseif(($start_x == ($cur_spot[0] + 1)) && ($start_y > == $cur_spot[1]) && (($area[east] != "0") && ($area[east] != > "")) && ($area[e_level] <= $user[level]) && (($area[e_level] > <= $user[level]) OR ($area[e_level] == $user[clan])) && > ($movement != "no")) > $map_display .= ""; > elseif(($start_x == $cur_spot[0] ) && ($start_y == > ($cur_spot[1]) - 1) && (($area[south] != "0") && > ($area[south] != "")) && ($area[s_level] <= $user[level]) && > (($area[s_level] <= $user[level]) OR ($area[s_level] == > $user[clan])) && ($movement != "no")) > $map_display .= ""; > elseif(($start_x == $cur_spot[0] ) && ($start_y == > ($cur_spot[1]) + 1) && (($area[north] != "0") && > ($area[north] != "")) && ($area[n_level] <= $user[level]) && > (($area[n_level] <= $user[level]) OR ($area[n_level] == > $user[clan])) && ($movement != "no")) > $map_display .= ""; > else > $map_display .= ""; > }else{ > $bg_color = ""; > $map_display .= ""; > } > $start_x += 1; > }while($n < 25); > ?> ">??
?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


?
?Optimizing Code
";
}
$test_area_query = mysql_query("SELECT * FROM ad_areas WHERE x = '$start_x' && y = '$start_y'", $my->connection);
if($test_area = mysql_fetch_array($test_area_query)){
$bg_color = "bgcolor='green'";
if(($start_x == $cur_spot[0]) && ($start_y == $cur_spot[1]))
$map_display .= "";
elseif(($start_x == ($cur_spot[0] - 1)) && ($start_y == $cur_spot[1]) && (($area[west] != "0") && ($area[west] != "")) && (($area[w_level] <= $user[level]) OR ($area[w_level] == $user[clan])) && ($movement != "no"))
$map_display .= "";
elseif(($start_x == ($cur_spot[0] + 1)) && ($start_y == $cur_spot[1]) && (($area[east] != "0") && ($area[east] != "")) && ($area[e_level] <= $user[level]) && (($area[e_level] <= $user[level]) OR ($area[e_level] == $user[clan])) && ($movement != "no"))
$map_display .= "";
elseif(($start_x == $cur_spot[0] ) && ($start_y == ($cur_spot[1]) - 1) && (($area[south] != "0") && ($area[south] != "")) && ($area[s_level] <= $user[level]) && (($area[s_level] <= $user[level]) OR ($area[s_level] == $user[clan])) && ($movement != "no"))
$map_display .= "";
elseif(($start_x == $cur_spot[0] ) && ($start_y == ($cur_spot[1]) + 1) && (($area[north] != "0") && ($area[north] != "")) && ($area[n_level] <= $user[level]) && (($area[n_level] <= $user[level]) OR ($area[n_level] == $user[clan])) && ($movement != "no"))
$map_display .= "";
else
$map_display .= "";
}else{
$bg_color = "";
$map_display .= "";
}
$start_x += 1;
}while($n < 25);
?>

Author:??(---.austin.rr.com)
Date:???07-28-04 08:04

Hello,

I've made a map for a game I am working on, where it queries the database for the surronding areas (each area is a differnt entry in the database) and shows the area you are currently in as the center of the areas. The code works, but is highly inefficient, and is starting to bog down my server because it queries the entire database about 25 times a page load. I know there is a way to do all of the following in one query, but even after spending a few days trying various methods, Ive finally decided to come for help, because its just out of my grasp. (The code is just the portion that loops around to determine if an area exists or not, and if it doesnt exist, it just puts an empty square, instead of a green colored one. It's IMPORTANT that the non-existant areas are recognised, and given the blank space, or else my map will be totally messed up, and not be in the geometrical X, Y, Z basis which is how the game navigates around...)

$cur_spot[0] = 0; // X axis
$cur_spot[1] = 0; // Y axis
$cur_spot[2] = 0; // Z axis

$area_query = mysql_query("SELECT * FROM ad_areas WHERE x = '$cur_spot[0]' && y = '$cur_spot[1]' && z = '$cur_spot[2]'", $my->connection);
if($area = mysql_fetch_array($area_query)){

$n = 0;
$start_y = $cur_spot[1] + 2;
$start_x = $cur_spot[0] - 2;
do{
$n += 1;
if((($n % 5) == 1) && ($n != 1)){
$start_y -= 1;
$start_x -= 5;
$map_display .= "
?WESN??

?Topics Author? Date
?Optimizing Code??new
Steven Hite 07-28-04 08:04?
?Re: Optimizing Code??new
bastien 07-28-04 09:13?
?Re: Optimizing Code??new
bastien 07-28-04 09:13?
?Re: Optimizing Code??new
bve 09-20-04 17:12?
Go to Top??|??Go to Topic??|??Flat View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??wrote: > > Hello, > > I've made a map for a game I am working on, where it queries > the database for the surronding areas (each area is a > differnt entry in the database) and shows the area you are > currently in as the center of the areas. The code works, but > is highly inefficient, and is starting to bog down my server > because it queries the entire database about 25 times a page > load. I know there is a way to do all of the following in > one query, but even after spending a few days trying various > methods, Ive finally decided to come for help, because its > just out of my grasp. (The code is just the portion that > loops around to determine if an area exists or not, and if it > doesnt exist, it just puts an empty square, instead of a > green colored one. It's IMPORTANT that the non-existant > areas are recognised, and given the blank space, or else my > map will be totally messed up, and not be in the geometrical > X, Y, Z basis which is how the game navigates around...) > > $cur_spot[0] = 0; // X axis > $cur_spot[1] = 0; // Y axis > $cur_spot[2] = 0; // Z axis > > $area_query = mysql_query("SELECT * FROM ad_areas WHERE x = > '$cur_spot[0]' && y = '$cur_spot[1]' && z = '$cur_spot[2]'", > $my->connection); > if($area = mysql_fetch_array($area_query)){ > > $n = 0; > $start_y = $cur_spot[1] + 2; > $start_x = $cur_spot[0] - 2; > do{ > $n += 1; > if((($n % 5) == 1) && ($n != 1)){ > $start_y -= 1; > $start_x -= 5; > $map_display .= "
height='25' $onclick width='25'>  height='25' > OnClick=\"location.href='javascript:document.forms.west.submit();'\" onmouseover=\"this.style.cursor='hand'\" width='25'>W height='25' > OnClick=\"location.href='javascript:document.forms.east.submit();'\" onmouseover=\"this.style.cursor='hand'\" width='25'>E height='25' > OnClick=\"location.href='javascript:document.forms.south.submit();'\" onmouseover=\"this.style.cursor='hand'\" width='25'>S height='25' > OnClick=\"location.href='javascript:document.forms.north.submit();'\" onmouseover=\"this.style.cursor='hand'\" width='25'>N height='25' $onclick width='25'>  height='25' $onclick width='25'> 

Provided By
Phorum