My guess is that you're relying on the order in which you put things into
the hash to be the same as the order in which they come out. There's no
guarantee that this is the case, as far as I know. You could use an array
and store hashrefs in it:
$locationh = $dbh->prepare_cached("select id,name from location where id<100
order by id");
$locationh ->execute();
$i=0;
while ($r=$locationh->fetchrow_hashref('NAME_lc')) {
$i++;
$loc[$i]=$r;
}
When you want to deal with the values:
for($j=0;$j<=$i;$j++) {
printf("<option
value=%s>%s</option>\n",$loc[$j]->{id},$loc[$j]->{name});
}
Hope this helps!
Gordon Dewis
Production Officer
Geography Division
Statistics Canada
(613)951-4591
-----Original Message-----
From: Hytham Shehab [mailto:[EMAIL PROTECTED]]
Sent: Thursday, July 25, 2002 3:37 PM
To: dbi
Subject: Re: it *should* be sorted, but it is not
here is a code snippet:
$locationh = $dbh->prepare_cached("select id,name from location where id<100
order by id");
$locationh ->execute();
while (@row=$locationh->fetchrow_array) {
$loc{$row[0]} = $row[1];
}
now, when i get the %loc and print it as a key,value pairs, it gives me the
wrong order:
<option value=2>zone2</option>
<option value=1>zone2</option>
which is not what i want, what i want is
<option value=1>zone1</option>
<option value=2>zone2</option>
thats it, i hope this could make it more clarified.
thanks guys
--
Hytham Shehab