zimmo Posted September 18, 2009 Share Posted September 18, 2009 I have an if else statement to check the data in a given table in the database. What I want is for one elseif statement to check if the field in the table contains .jpg how can I do this with the following: if ($row[pic] =="") { echo ("\n"); } elseif ($row[pic] =="A") { echo (" Standard A \n"); } elseif ($row[frontcoverpic] ==".jpg") { echo ("You chose the image\n"); } I know the third statement is incorrect, what I need is to be able to check if the field contains the .jpg how do I do this Link to comment https://forums.phpfreaks.com/topic/174694-if-else-query/ Share on other sites More sharing options...
ram4nd Posted September 18, 2009 Share Posted September 18, 2009 well thats right then. Link to comment https://forums.phpfreaks.com/topic/174694-if-else-query/#findComment-920650 Share on other sites More sharing options...
kickstart Posted September 18, 2009 Share Posted September 18, 2009 if ($row[pic] =="") { echo ("\n"); } elseif ($row[pic] =="A") { echo (" Standard A \n"); } elseif (strtolower(substr($row[frontcoverpic],-4,4)) ==".jpg") { echo ("You chose the image\n"); } That would check if it ends in .jpg (case insensitive). However is the data coming from a table? Why not store the file extension in a seperate column? All the best Keith Link to comment https://forums.phpfreaks.com/topic/174694-if-else-query/#findComment-920652 Share on other sites More sharing options...
Bricktop Posted September 18, 2009 Share Posted September 18, 2009 Hi zimmo, This should do the trick: if ($row[pic] =="") { echo ("\n"); } elseif ($row[pic] =="A") { echo (" Standard A \n"); } elseif (strtolower(substr($row[frontcoverpic], strlen($row[frontcoverpic])-3)) == 'jpg')) { echo ("You chose the image\n"); } Hope this helps. Link to comment https://forums.phpfreaks.com/topic/174694-if-else-query/#findComment-920653 Share on other sites More sharing options...
zimmo Posted September 18, 2009 Author Share Posted September 18, 2009 Bricktop... works a treat.. many thanks Link to comment https://forums.phpfreaks.com/topic/174694-if-else-query/#findComment-920662 Share on other sites More sharing options...
kickstart Posted September 18, 2009 Share Posted September 18, 2009 Hi Substr can take a negative parameter and just work from the end. No need to find the length and subtract from it in php. All the best Keith Link to comment https://forums.phpfreaks.com/topic/174694-if-else-query/#findComment-920664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.