Jump to content

if else query


zimmo

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.