Reputation: 1
I'm really still learning php and this time can't implement this piece of code. I need some help please.
I have this query:
$query = tep_db_query("select c.categories_id, c.categories_image, cd.categories_name,
c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . "
cd where c.parent_id = '0' and c.categories_id IN ('25', '29', '41') and
c.categories_id = cd.categories_id order by cd.categories_name ASC");
As a result, I got this array:
Array ( [41] => Acura Parts and Accessories [29] => Honda Exterior Accessories
[25] => Toyota Engine Parts)
I have created this short category name array:
$shortNames = array('25' => 'Toyota', '29' => 'Honda', '41' => 'Acura');
I need to instead of echo the long category name in the following code, match the id and echo the short name.
while ($categories = tep_db_fetch_array($categories_query)) {
<a href="<?php echo tep_href_link(FILENAME_DEFAULT, 'cPath='.$categories['categories_id']); ?>">
<?php echo $categories['categories_name']; ?>
</a>
}
I have been looking at some foreach samples but can't really get into this.
Thank you!!!
Upvotes: 0
Views: 46
Reputation: 2229
Well, if I understood what you are trying to do, it would be something like this:
while ($categories = tep_db_fetch_array($categories_query)){
$categoryId = $categories['categories_id'];
$shortName = $shortNames[$categoryId];
$href = tep_href_link(FILENAME_DEFAULT,'cPath='.$categoryId);
echo '<a href="'.$href.'">$shortName</a>';
}
Upvotes: 2