Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2011, 06:34 PM   PM User | #1
battlefieldmax
New Coder

 
Join Date: Jan 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
battlefieldmax is an unknown quantity at this point
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?
battlefieldmax is offline   Reply With Quote
Old 01-29-2011, 06:45 PM   PM User | #2
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 01-29-2011, 08:46 PM   PM User | #3
battlefieldmax
New Coder

 
Join Date: Jan 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
battlefieldmax is an unknown quantity at this point
I will try that

and

What should I stick it in then?
battlefieldmax is offline   Reply With Quote
Old 01-29-2011, 09:12 PM   PM User | #4
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 01-29-2011, 09:31 PM   PM User | #5
battlefieldmax
New Coder

 
Join Date: Jan 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
battlefieldmax is an unknown quantity at this point
You said don't stink it in a table what should I stick it in then?
battlefieldmax is offline   Reply With Quote
Old 01-29-2011, 09:39 PM   PM User | #6
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 01-29-2011, 09:45 PM   PM User | #7
battlefieldmax
New Coder

 
Join Date: Jan 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
battlefieldmax is an unknown quantity at this point
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?
battlefieldmax is offline   Reply With Quote
Old 01-29-2011, 09:50 PM   PM User | #8
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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
oesxyl is offline   Reply With Quote
Old 01-29-2011, 09:51 PM   PM User | #9
battlefieldmax
New Coder

 
Join Date: Jan 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
battlefieldmax is an unknown quantity at this point
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..
battlefieldmax is offline   Reply With Quote
Old 01-30-2011, 07:06 AM   PM User | #10
RoMa
New Coder

 
Join Date: Jan 2011
Posts: 49
Thanks: 0
Thanked 7 Times in 7 Posts
RoMa is an unknown quantity at this point
I'm confused by what you're asking/wanting.. Are you wanting to change the cell color if it's being occupied?
RoMa is offline   Reply With Quote
Old 01-31-2011, 03:13 AM   PM User | #11
battlefieldmax
New Coder

 
Join Date: Jan 2011
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
battlefieldmax is an unknown quantity at this point
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..
battlefieldmax is offline   Reply With Quote
Reply

Bookmarks

Tags
game, php, script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:35 AM.


Advertisement
Log in to turn off these ads.