chuddyuk Posted June 2, 2006 Share Posted June 2, 2006 Im trying to replace data from the database with different words:[code]if ($collection = 'ethnicchic'){echo "Ethnic Chic";}elseif ($collection = 'indiansummer'){echo "Indian Summer";}elseif ($collection = 'africaninspirations'){echo "African Inspirations";}elseif ($collection = 'contemporarycreations'){echo "Contemporary Creations";}[/code]i am using the above code to try and change whats in the databse to something else, in this case to put a space betweeen my letters. but it doesnt change anything. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/11011-if-function/ Share on other sites More sharing options...
AndyB Posted June 2, 2006 Share Posted June 2, 2006 == is the comparison operator. Change your code to this:[code]if ($collection == 'ethnicchic'){echo "Ethnic Chic";}elseif ($collection == 'indiansummer'){echo "Indian Summer";}elseif ($collection == 'africaninspirations'){echo "African Inspirations";}elseif ($collection == 'contemporarycreations'){echo "Contemporary Creations";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11011-if-function/#findComment-41132 Share on other sites More sharing options...
kenrbnsn Posted June 2, 2006 Share Posted June 2, 2006 You don't need to use the "elseif" in this instance, since you could write this as four individual "if" statements:[code]<?phpif ($collection == 'ethnicchic') echo "Ethnic Chic";if ($collection == 'indiansummer') echo "Indian Summer";if ($collection == 'africaninspirations') echo "African Inspirations";if ($collection == 'contemporarycreations') echo "Contemporary Creations";?>[/code]You can also use a "switch" statement here:[code]<?phpswitch ($collection) { case 'ethnicchic': $tmp = 'ethnic chic'; break; case 'indiansummer': $tmp = 'indian summer'; break; case 'africaninspirations': $tmp = 'african inspirations'; break; case 'contemporarycreations': $tmp = 'contemporary creations'; break;}echo ucwords($tmp);?>[/code]Just giving you other options.Ken Quote Link to comment https://forums.phpfreaks.com/topic/11011-if-function/#findComment-41136 Share on other sites More sharing options...
chuddyuk Posted June 2, 2006 Author Share Posted June 2, 2006 Thanks alot that worked well good for me!!!!:):) Quote Link to comment https://forums.phpfreaks.com/topic/11011-if-function/#findComment-41284 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.