Re: how to.. arrays? :D
| From: | Hawk | Date: | Wed, 08 May 2002 21:37:51 +0000 |
| Subject: | Re: how to.. arrays? :D | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96681@lists.php.net to get a copy of this message | ||
The reason why I want to use arrays is that I have to get the first and
second line from every group, and combine them in a special way, inside a
table, and I have the feeling it will be easier to use arrays than to make a
mysql connection for every $, and anyway, may I have some help with arrays,
might be good to know in the future :)
I managed with normal arrays, but I can't figure it out how to do in a loop
I have like:
$g = 0;
while ($g < mysql_num_row($something)) { print "some stuff";$r = 0;while ($r
< mysql_num_rows($somethingelse)) { print "some other stuff"; $teama =
array('$g' => array('$r' => '$tnme'));$r++; }}
but that aint working :D
Håkan
"Erik Price" <pricee@hhbrown.com> skrev i meddelandet
news:1DE14B82-62CA-11D6-8E8E-0050E4857868@hhbrown.com...
>
> 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
>