themeatpuppet Posted July 28, 2007 Share Posted July 28, 2007 I'm pulling out links from a database, some of them are images, some are movies, some are URLs and some are just download files. I need a way to differentiate each of the to be printed in the anchor tag this is what I'm doing: for($j=0;$j<count($links);$j++) { // explode on '.' to separate string $link_path = explode('.',$links['link_path']); // get last element for extension $link_path=$link_path[count($link_path)-1]; if($link_path=='jpg'|| $link_path=='gif'|| $link_path=='png'|| $link_path=='JPG'|| $link_path=='jpeg'|| $link_path=='JPEG'|| $link_path=='GIF'|| $link_path=='PNG'|| $link_path=='swf'|| $link_path=='SWF') { $link_image = getimagesize($folder.'/'.links['link_path']); $link_location = $folder.'/'; $link_target = "\" onclick=\"popUp(this.href,'console',$link_image[1],$link_image[0]);return false;\" target=\"newWin\">"; } elseif($link_path=='cfm'||$link_path='htm'||$link_path='html') { $link_location = $folder.'/'; $link_target = '">'; } else { $link_location=''; $link_target = '">'; } $links_div .='<li><a href="'.$link_location.$links['link_path'].$link_target.$links['link_name'].'</a>'; if(($i!=count($links))||$i==0) { $links_div .= " | </li>"; } else { $links_div .= "</li>"; } } Well the idea makes sense to me, but for some reason i don't understand, the loop is skipping the last else statement and those links that should be processed as such end up as the second elseif. It's like a riddle ??? ??? Link to comment https://forums.phpfreaks.com/topic/62161-getting-file-type-from-a-string-into-anchor/ Share on other sites More sharing options...
GingerRobot Posted July 28, 2007 Share Posted July 28, 2007 Simple typo. Change this line: } elseif($link_path=='cfm'||$link_path='htm'||$link_path='html') { to } elseif($link_path=='cfm'||$link_path=='htm'||$link_path=='html') { You were using a single equals sign, which is the assignment operator. It will always evaluate to true, so that elseif would never fail. Link to comment https://forums.phpfreaks.com/topic/62161-getting-file-type-from-a-string-into-anchor/#findComment-309449 Share on other sites More sharing options...
themeatpuppet Posted July 28, 2007 Author Share Posted July 28, 2007 blast! i tought i've corrected that before, i cant believe it was actually that, i guess with so many of them i got kungfused thanks! Link to comment https://forums.phpfreaks.com/topic/62161-getting-file-type-from-a-string-into-anchor/#findComment-309577 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.