ballhogjoni Posted December 10, 2008 Share Posted December 10, 2008 Does anyone know how to do this? I ask because I am generating a where clause for mysql and I can't have an AND at the end of the where clause. Ex: affiliate_id = "47" AND affiliate_id = "43" AND affiliate_id = "85" AND affiliate_id = "337" AND affiliate_id = "341" AND my code foreach( $aAffiliates as $key => $value ){ $sWhere .= 'affiliate_id = "'.$value['id'].'" AND '; } Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/ Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 Why not use the implode <?php $sWhere = implode("' AND '", $aAffiliates); Should get what you want =) Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711957 Share on other sites More sharing options...
rhodesa Posted December 10, 2008 Share Posted December 10, 2008 instead, use: $sWhere = array(); foreach( $aAffiliates as $key => $value ){ $sWhere[] = 'affiliate_id = "'.$value['id'].'"'; } $sWhere = implode(' AND ',$sWhere); Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711959 Share on other sites More sharing options...
ballhogjoni Posted December 10, 2008 Author Share Posted December 10, 2008 $aAffiliates is a multi array Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711962 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 $aAffiliates is a multi array Yea, look at rhodesa's example. I just missed that it was a mutli-dimm array. =) Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711964 Share on other sites More sharing options...
ballhogjoni Posted December 10, 2008 Author Share Posted December 10, 2008 Aaron, ty that works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711965 Share on other sites More sharing options...
DarkWater Posted December 10, 2008 Share Posted December 10, 2008 By the way, are you sure you want AND and not OR? =P If you did really mean OR, I'd suggest just checking out the IN() construct. It would make your life much easier. Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711968 Share on other sites More sharing options...
ballhogjoni Posted December 10, 2008 Author Share Posted December 10, 2008 yep thx for the help. Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711970 Share on other sites More sharing options...
ballhogjoni Posted December 10, 2008 Author Share Posted December 10, 2008 Nope need AND Quote Link to comment https://forums.phpfreaks.com/topic/136424-solved-how-to-find-the-last-index-in-an-array/#findComment-711971 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.