Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Really confused and lost.. trouble with PHP/MySQL

    this is my code, i will explain below..

    PHP Code:
    $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 && $y2 && $y3 && $y4 && $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.

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Someone please help... i need this to work asap

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    But i echoed them in the same portion of the code as the update.. right below it.. it should be the exact same numbers..

  • #5
    Regular Coder
    Join Date
    Jan 2006
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oh my god.. im embarrassed.. I changed the UPDATE statement to:

    PHP Code:
    mysql_query("UPDATE userinf SET xpos='1',ypos='$whichkingdom',zpos='$nextz' WHERE username='".$retval['username']."' "$db); 
    and it works fine.. wow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •