Register | Login | |||||
Main
| Memberlist
| Active users
| ACS
| Commons
| Calendar
| Online users Ranks | FAQ | Color Chart | Photo album | IRC Chat |
| |
0 user currently in Programming. | 3 guests |
Acmlm's Board - I2 Archive - Programming - Weird PHP array problem | | | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
User | Post | ||
windwaker Ball and Chain Trooper WHY ALL THE MAYONNAISE HATE Level: 61 Posts: 789/1797 EXP: 1860597 For next: 15999 Since: 03-15-04 Since last post: 4 days Last activity: 6 days |
| ||
$batusers = mysql_query("SELECT * FROM `users` WHERE `inbattle` = '". $batid[id] ."' ORDER BY `id` DESC LIMIT 10" This echoes "213wa5wa211320030153553". When I use print_r($batusers), I get Array ( [id] => 2 [maxhp] => 100 [maxmp] => 30 [name] => windwaker [password] => ab17850978e36aaf6a2b8808f1ded971 [money] => 500 [email] => windwaker101@gmail.com [avatar] => avatars/locke.gif [level] => 2 [exp] => 1000 [hp] => 100 [mp] => 30 [weapon] => 2 [item1] => 0 [item2] => 0 [inbattle] => 35 [subweapon] => 0 [location] => 1 [attack] => 500 [turns] => 300 [magicpower] => 50 [defense] => 50 [speed] => 30 ) What's wrong here? |
|||
Gywall Silver axe Level: 30 Posts: 291/356 EXP: 164069 For next: 1800 Since: 03-15-04 From: In front of my moniter, where you're not! Since last post: 104 days Last activity: 14 hours |
| ||
Originally posted by windwaker$batusers = mysql_query("SELECT * FROM `users` WHERE `inbattle` = '". $batid[id] ."' ORDER BY `id` DESC LIMIT 10" use , and not => It should make a difference. Hell, I've used arrays before. |
|||
Dylan Devil Trumpets and Angel Trombones ~ Level: 54 Posts: 1233/1407 EXP: 1181697 For next: 52173 Since: 06-19-04 From: Ottawa, Canada. Since last post: 1 day Last activity: 6 hours |
| ||
Originally posted by windwaker An array consists of a key and a value. Like: $this = array( 'key' => 'value', 'key' => 'value', 'key' => 'value' ); But you don't always need a key, its just an identifier associated with a value. So if you just have the value, use commas. Like: $this = array('value', value', 'value'); |
|||
windwaker Ball and Chain Trooper WHY ALL THE MAYONNAISE HATE Level: 61 Posts: 792/1797 EXP: 1860597 For next: 15999 Since: 03-15-04 Since last post: 4 days Last activity: 6 days |
| ||
Originally posted by GywallOriginally posted by windwaker$batusers = mysql_query("SELECT * FROM `users` WHERE `inbattle` = '". $batid[id] ."' ORDER BY `id` DESC LIMIT 10" Array ( [id] => 2 [maxhp] => 100 [maxmp] => 30 [name] => windwaker [password] => ab17850978e36aaf6a2b8808f1ded971 [money] => 500 [email] => windwaker101@gmail.com [avatar] => avatars/locke.gif [level] => 2 [exp] => 1000 [hp] => 100 [mp] => 30 [weapon] => 2 [item1] => 0 [item2] => 0 [inbattle] => 35 [subweapon] => 0 [location] => 1 [attack] => 500 [turns] => 300 [magicpower] => 50 [defense] => 50 [speed] => 30 ) <-- this is what is echoed by print_r; the array is created with: $batusers = mysql_query("SELECT * FROM `users` WHERE `inbattle` = '". $batid[id] ."' ORDER BY `id` DESC LIMIT 10" $batusers = mysql_fetch_array($batusers, MYSQL_ASSOC); |
|||
Dylan Devil Trumpets and Angel Trombones ~ Level: 54 Posts: 1234/1407 EXP: 1181697 For next: 52173 Since: 06-19-04 From: Ottawa, Canada. Since last post: 1 day Last activity: 6 hours |
| ||
Um, didn't you just post your erroneous array? Uh, use a comma instead of this deal => Eep! pre text! Table stretching! (edited by Dylan on 12-24-04 05:18 PM) |
|||
windwaker Ball and Chain Trooper WHY ALL THE MAYONNAISE HATE Level: 61 Posts: 793/1797 EXP: 1860597 For next: 15999 Since: 03-15-04 Since last post: 4 days Last activity: 6 days |
| ||
*ww is confused* What do you mean, use a comma instead? That's exactly what print_r($batusers) echoed; I didn't make the array myself, it came from a mysql_query. |
|||
Vystrix Nexoth Level: 30 Posts: 202/348 EXP: 158678 For next: 7191 Since: 03-15-04 From: somewhere between anima and animus Since last post: 3 days Last activity: 2 days |
| ||
foreach($batusers as $name){ You are aware that $name is not an array, yes? You ought not treat it as though it were. |
|||
windwaker Ball and Chain Trooper WHY ALL THE MAYONNAISE HATE Level: 61 Posts: 795/1797 EXP: 1860597 For next: 15999 Since: 03-15-04 Since last post: 4 days Last activity: 6 days |
| ||
Ah, okay, now I see. So now I did foreach($batusers['name'] as $name), and it worked. Thanks guys. |
|||
Vystrix Nexoth Level: 30 Posts: 204/348 EXP: 158678 For next: 7191 Since: 03-15-04 From: somewhere between anima and animus Since last post: 3 days Last activity: 2 days |
| ||
...$batusers['name'] is not an array either.as discussed on IRC, what you were looking for was: $resultset = mysql_query ("SELECT hp, name, etc FROM users WHERE whatever"); |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
Acmlm's Board - I2 Archive - Programming - Weird PHP array problem | | | |