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 '; } 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 =) 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); 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 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. =) 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. 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. 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. 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 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
Archived
This topic is now archived and is closed to further replies.