Jump to content


Photo

if function


  • Please log in to reply
3 replies to this topic

#1 chuddyuk

chuddyuk
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationEngland

Posted 02 June 2006 - 09:03 AM

Im trying to replace data from the database with different words:
if ($collection = 'ethnicchic'){
echo "Ethnic Chic";
}
elseif ($collection = 'indiansummer'){
echo "Indian Summer";
}
elseif ($collection = 'africaninspirations'){
echo "African Inspirations";
}
elseif ($collection = 'contemporarycreations'){
echo "Contemporary Creations";
}
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?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 02 June 2006 - 11:29 AM

== is the comparison operator. Change your code to this:
if ($collection == 'ethnicchic'){
echo "Ethnic Chic";
}
elseif ($collection == 'indiansummer'){
echo "Indian Summer";
}
elseif ($collection == 'africaninspirations'){
echo "African Inspirations";
}
elseif ($collection == 'contemporarycreations'){
echo "Contemporary Creations";
}

Legend has it that reading the manual never killed anyone.
My site

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 June 2006 - 11:50 AM

You don't need to use the "elseif" in this instance, since you could write this as four individual "if" statements:
<?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";
?>
You can also use a "switch" statement here:
<?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);
?>

Just giving you other options.

Ken

#4 chuddyuk

chuddyuk
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationEngland

Posted 02 June 2006 - 07:34 PM

Thanks alot that worked well good for me!!!!:):)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users