...

View Full Version : Really confused and lost.. trouble with PHP/MySQL



king2k5
03-17-2008, 02:38 AM
this is my code, i will explain below..


$result_move = mysql_query("SELECT * FROM userinf WHERE xpos='99' AND ypos='99' AND score>='50000' AND bactiv='1' ", $db);
while($retval = mysql_fetch_array($result_move)) {



$result_y1 = mysql_query("SELECT * FROM userinf WHERE ypos='1'", $db);
if(mysql_num_rows($result_y1)) {

$retval_y1 = mysql_fetch_array($result_y1);

$y1 = mysql_num_rows($result_y1);

}else{

$y1 = 0;

}
$result_y2 = mysql_query("SELECT * FROM userinf WHERE ypos='2'", $db);
if(mysql_num_rows($result_y2)) {

$retval_y2 = mysql_fetch_array($result_y2);

$y2 = mysql_num_rows($result_y2);

}else{

$y2 = 0;

}
$result_y3 = mysql_query("SELECT * FROM userinf WHERE ypos='3'", $db);
if(mysql_num_rows($result_y3)) {

$retval_y3 = mysql_fetch_array($result_y3);

$y3 = mysql_num_rows($result_y3);

}else{

$y3 = 0;

}
$result_y4 = mysql_query("SELECT * FROM userinf WHERE ypos='4'", $db);
if(mysql_num_rows($result_y4)) {

$retval_y4 = mysql_fetch_array($result_y4);

$y4 = mysql_num_rows($result_y4);

}else{

$y4 = 0;

}
$result_y5 = mysql_query("SELECT * FROM userinf WHERE ypos='5'", $db);
if(mysql_num_rows($result_y5)) {

$retval_y5 = mysql_fetch_array($result_y5);

$y5 = mysql_num_rows($result_y5);

}else{

$y5 = 0;

}

if($y1 > 0 && $y2 > 0 && $y3 > 0 && $y4 > 0 && $y5 > 0){
$whichkingdom = min($y1,$y2,$y3,$y4,$y5);
}elseif($y1==0){

$whichkingdom = 1;

}elseif($y2==0){

$whichkingdom = 2;

}elseif($y3==0){

$whichkingdom = 3;

}elseif($y4==0){

$whichkingdom = 4;

}elseif($y5==0){

$whichkingdom = 5;

}

$result_z = mysql_query("SELECT MAX(zpos) FROM userinf WHERE xpos='1' AND ypos='$whichkingdom' AND bactiv='1'", $db);

if(!mysql_num_rows($result_z)) {

$nextz = 1;

}else{
$retval_z = mysql_fetch_array($result_z);



$nextz = $retval_z['MAX(zpos)']+1;
}

$result_king = mysql_query("SELECT * FROM kinginf WHERE xpos='1' AND ypos='$whichkingdom'", $db);
if(!mysql_num_rows($result_king)) {

mysql_query("INSERT INTO kinginf(kname,xpos,ypos,klogo) VALUES ('No name','1','$whichkingdom','0')", $db);


}else{



}

mysql_query("UPDATE userinf SET xpos='1' AND ypos='$whichkingdom' AND zpos='$nextz' WHERE username='".$retval['username']."' ", $db);


echo "".$retval['username'].": YPOS: $whichkingdom, ZPOS: $nextz<br>";

}

This code is designed to move a player, from the initial kingdom(99:99), to a new kingdom when he/she has reached a certain score. xpos, ypos, and zpos are the kingdom coordinates. xpos:ypos:zpos. Now, i have the xpos to always be 1, and i have the ypos chosen from 1 - 5, whichever has the lowest amount of people in it. The zpos is calculated from how many people are in the kingdom+1. The trouble, however... is that this is not working at all.. I have one person that im testing this on, with the username of ISetFlysOnFire.. now.. when the script runs.. it moves him to the following coordinates: 0:99:47.. that makes NO SENSE, based on the code.. so i decided to echo it.. the echo tells me: ISetFlysOnFire: YPOS: 2, ZPOS: 1. This is correct.. but thats not what is going into the database, which is just a line above, and uses the same variables.. and whats even more confusing.. is that in my UPDATE statement.. i have SET xpos='1'.. and its setting it to 0 for some reason.. Any help would be very much appreciated.

king2k5
03-17-2008, 03:55 PM
Someone please help... i need this to work asap

InsaneRhino
03-17-2008, 04:58 PM
Try echoing your $whichkingdom and $nextz variables at different stages to see what they are and when they are changing.

This might give you an indication as to at what point the code is screwing up.

king2k5
03-17-2008, 06:50 PM
But i echoed them in the same portion of the code as the update.. right below it.. it should be the exact same numbers..

king2k5
03-17-2008, 07:06 PM
Oh my god.. im embarrassed.. I changed the UPDATE statement to:


mysql_query("UPDATE userinf SET xpos='1',ypos='$whichkingdom',zpos='$nextz' WHERE username='".$retval['username']."' ", $db);


and it works fine.. wow



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum