Re: Hashes
| From: | Robert Weeks | Date: | Fri, 21 Dec 2001 21:29:24 +0000 |
| Subject: | Re: Hashes | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-15190@lists.php.net to get a copy of this message | ||
Thanks,
Your assumptions were correct, I'll give that a try.
I ended up doing this which doesn't seem as efficient:
$item_array = array('Mens Ring' => m_r,
'Mens Charm' => m_c,
'Womens Ring' => w_r,
'Womens Charm' => w_c
);
while (list($val, $key) = each($item_array)){
if ($key == $item){
$item_text = $val;
}
}
echo $item_text;
Thanks again,
Robert
----- Original Message -----
From: "Matthew Loff" <matt@willetts.com>
To: "'Robert Weeks'" <robert@woozy.com>; <php-db@lists.php.net>
Sent: Friday, December 21, 2001 4:26 PM
Subject: RE: [PHP-DB] Hashes
>
> Robert--
>
> You're on the right track... I'm assuming $row is the result of a
> mysql_fetch_assoc() call, and $row['item'] contains the hashed value
> (either "m_r", "m_c", or whatever)... Try this:
>
> <?php
>
> $item_list = array('Mens Ring' => m_r, 'Mens Charm' => m_c,
> 'Womens
> Ring' => w_r,'Womens Charm' => w_c);
>
> #query db and get a result snipped
>
> echo $item_list[$row['item']];
>
> ?>
>
> Good luck,
> Matt
>
>
> -----Original Message-----
> From: Robert Weeks [mailto:robert@woozy.com]
> Sent: Friday, December 21, 2001 11:27 AM
> To: php-db@lists.php.net
> Subject: [PHP-DB] Hashes
>
>
> I'm trying to use a hash to translate a value into something human
> readable. I know how to do this with an if-else but that seems like a
> waste of typing.
>
> I have a bunch of items in the db and their values are abbreciations
> such as 'm_r'. I want m_r to show on the page as "Mens Rings". I was
> trying to do it like this but echo $item returned "Array":
> <?php
>
> #query db and get a result snipped
>
> $item = $row[item];
>
> $item = array('Mens Ring' => m_r, 'Mens Charm' => m_c, 'Womens
> Ring' =>
> w_r,'Womens Charm' => w_c);
>
> echo $item;
>
> ?>
>
> Any help would be appreciated.
>
> thnx,
>
> robert
>
>
>
>