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 11 of 11

Thread: PHP loop....

  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question PHP loop....

    I'm creating a game and I have gotten most of it done but It only shows one person on the map, because I'm using WHERE ecy='ect'
    But if I take out the WHERE I get one map for every person on the page
    PHP Code:
    $result2 mysql_query("SELECT * FROM members WHERE (removed) "); 
    PHP Code:
    while($row2 mysql_fetch_array($result2))
      { 
    Here is the code to display the characters
    PHP Code:
    <?php if ($position != A2) { ?> <td bgcolor="#0000CC" width="23" height="23"></td><?php } else { ?> 
    <td bgcolor="#0000CC" width="10" height="10"><img src="<?php echo "$army/$character_type" ?>.png" alt="<?php $username ?>" width="10" height="10"></td><?php ?>
    Can I change the WHILE to something that won't make it loop?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by battlefieldmax View Post
    Can I change the WHILE to something that won't make it loop?
    maybe this:

    http://www.php.net/manual/en/functio...-fetch-row.php

    or one of the function which starts with mysql_fetch_ from same link and do what you want.

    but the real problem is the mysql query, dumping all the data from a table is not a good idea.

    best regards

  • #3
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will try that

    and

    What should I stick it in then?

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by battlefieldmax View Post
    I will try that

    and

    What should I stick it in then?
    in mysql query or arguments of mysql_fetch?

    best regards

  • #5
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You said don't stink it in a table what should I stick it in then?

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by battlefieldmax View Post
    You said don't stink it in a table what should I stick it in then?
    i don't know what you mean by stink/stick, what i said is there is not a good idea to use such a query 'select * from member' because this will fetch avery row and every field in the row, that mean every thing you have in the table. Since you use only a small amount of all this data why do you query for all?

    best regards

  • #7
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I only made it this way because that's the only way I know how to do it.

    I can post full code and you could tell how I should do it?

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by battlefieldmax View Post
    I only made it this way because that's the only way I know how to do it.

    I can post full code and you could tell how I should do it?
    no need to post the code, just:
    - the name of the fields you need to use in the page and the name of the tables where they are
    - describe the relations between tables
    - describe what do you want to get from database

    best regards

  • #9
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basically the code is above that's about what the whole files looks like

    Table's are used as a map

    From the database is characters and army.

    Files is used here
    http://frontlines.cz.cc (you have to register to see the script game)

    If you see the game.php files it should explain it the best way.
    Last edited by battlefieldmax; 01-29-2011 at 10:13 PM.

  • #10
    New Coder
    Join Date
    Jan 2011
    Posts
    49
    Thanks
    0
    Thanked 7 Times in 7 Posts
    I'm confused by what you're asking/wanting.. Are you wanting to change the cell color if it's being occupied?

  • #11
    New Coder
    Join Date
    Jan 2011
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    When you try to make it so it shows every one on the map (taking WHERE out) It makes one map for every person.

    I need it to make on map with every one on it.

    EDIT: I found away to take out the while so it doesn't loop, But now it just doesn't show every one on the map . New code
    PHP Code:
    $result2 mysql_query("SELECT * FROM members "); 
    PHP Code:
    $row2 mysql_fetch_array($result2
    PHP Code:
    <?php if ($position != A2) { ?> <td bgcolor="#0000CC" width="23" height="23"></td><?php } else { ?> 
    <td bgcolor="#0000CC" width="10" height="10"><img src="<?php echo "$army/$character_type" ?>.png" alt="<?php $username ?>" width="10" height="10"></td><?php ?>
    Any one know how to get it to show now?
    Last edited by battlefieldmax; 01-31-2011 at 04:47 PM.


  •  

    Tags for this Thread

    Posting Permissions

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