jaxdevil Posted May 26, 2008 Share Posted May 26, 2008 I have a field called `cats` and in it it has all of the categories and subcategories, seperated by the delimiter '|' and they are in hierarchical order, the main category is first, then the subcategory, then the sub-subcategory, etc. I need to display the final subcategory in a row display, I can break up the data with explode but I do not know how to select the last text, the final subcategory after the last |. Here is an example of how the categories field (called `cats` in the database) looks for one example. The problem is some of the fields have a category, and a subcategory, and some have category, subcategory, and sub-subcategory, etc. So I can't just display say the 4th array, I have to make it display what is after the last delimiter. here is an exmaple of the categories field: consumer electronics|portable audio|mp3 and mp4 players|ipod And here is the entire code I have now: <?php mysql_connect('localhost','xxx','xxx'); mysql_select_db('xxx') or die(mysql_error()); ?> <xml version="1.0" encoding="UTF-8"> <rss version ="2.0" xmlns:g="http://base.google.com/ns/1.0"> <channel> <title>GS Wholesale</title> <description>Your Consumer Electronics and More Store!</description> <link>http://GSWholesale.com</link> <?php $sql = "SELECT * FROM products WHERE `active`='Yes' ORDER BY `cats` LIMIT 5" or die ( "Query failed due to: ".mysql_error()); $query = mysql_query($sql); while($row = mysql_fetch_array($query)) { $cats = explode("|",$row['cats']); ?> <item><title><?=$row['man']?> <?=$row['mod']?> <?=$row['name']?></title> <g:brand><?=$row['mod']?></g:brand> <g:condition>new</g:condition> <g:description><?=$row['description']?> <?=$row['details']?></g:description> <g:model_number><?=$row['mod']?></g:model_number> <g:id><?=$row['mod']?></g:id> <g:image_link><?=$row['img_url']?></g:image_link> <g:pickup>true</g:pickup> <g:link>http://GSWholesale.com/product.php?id=<?=$row['mod']?></g:link> <g:mpn><?=$row['mod']?></g:mpn> <g:price><?=$row['price']?></g:price> <g:product_type><?=$cats?></g:product_type> <g:upc><?=$row['upc']?></g:upc> <g:quantity>1000</g:quantity> <g:payment_accepted>Google Checkout</g:payment_accepted> <g:payment_accepted>PayPal</g:payment_accepted> <g:payment_accepted>Visa</g:payment_accepted> <g:payment_accepted>Mastercard</g:payment_accepted> <g:payment_accepted>American Express</g:payment_accepted> <g:payment_accepted>Discover</g:payment_accepted> <g:payment_accepted>Cash</g:payment_accepted> <g:payment_accepted>Checks</g:payment_accepted> <g:payment_accepted>Cashiers Checks</g:payment_accepted> <g:payment_accepted>Money Orders</g:payment_accepted> <g:payment_accepted>Wire Transfer</g:payment_accepted> </item> </channel></rss> <? } ?> Any help is greatly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/107262-solved-displaying-the-text-that-is-after-the-last-delimiter-in-a-field/ Share on other sites More sharing options...
.josh Posted May 26, 2008 Share Posted May 26, 2008 $last = last($cats); edit: sorry.. end($cats); Quote Link to comment https://forums.phpfreaks.com/topic/107262-solved-displaying-the-text-that-is-after-the-last-delimiter-in-a-field/#findComment-549983 Share on other sites More sharing options...
jaxdevil Posted May 26, 2008 Author Share Posted May 26, 2008 You da man! Quote Link to comment https://forums.phpfreaks.com/topic/107262-solved-displaying-the-text-that-is-after-the-last-delimiter-in-a-field/#findComment-549985 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.