Jump to content

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/11011-if-function/
Share on other sites

== 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]
Link to comment
https://forums.phpfreaks.com/topic/11011-if-function/#findComment-41132
Share on other sites

You don't need to use the "elseif" in this instance, since you could write this as four individual "if" statements:
[code]<?php
if ($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]<?php
switch ($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
Link to comment
https://forums.phpfreaks.com/topic/11011-if-function/#findComment-41136
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.