Re: how to.. arrays? :D

From: Date: Wed, 08 May 2002 21:25:27 +0000
Subject: Re: how to.. arrays? :D
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-96678@lists.php.net to get a copy of this message
On Wednesday, May 8, 2002, at 05:11 PM, Hawk wrote:
Ok, the last time(about 5 min ago) you told me to use arrays, to be honest I've never worked with arrays before, and I tried a little now, and I can't figure out how to make multi level arrays with a loop, I tried with $team = array($g => array($r => $tnme));
If you're just trying to sort the data ASC, you will probably be best served by performing your logic at the level of the database, NOT in PHP. PHP can do it, but it's more elegant to hand the data from the database over to PHP. Possibly faster, too, though I'm not sure about that. This may help you: mysql> CREATE TEMPORARY TABLE temptable (column1 TINYINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, column2 VARCHAR(10)); Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO temptable (column2) VALUES ('1234'), ('2345'), ('27'), ('100000'); Query OK, 4 rows affected (0.00 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> SELECT column2 FROM temptable ORDER BY column2 ASC; +---------+ | column2 | +---------+ | 100000 |
| 1234    |
| 2345    |
| 27      |
+---------+ 4 rows in set (0.03 sec) mysql> SELECT column2 + 0 AS column2 FROM temptable ORDER BY column2 ASC; +---------+ | column2 | +---------+
|      27 |
|    1234 |
|    2345 |
| 100000 | +---------+ 4 rows in set (0.01 sec) See that? by adding 0 to each value selected (and aliasing the selected values as "column2"), you end up getting the sort order you want. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#96678) next »