0

I am trying to return a different status for a property based on the department it is in. There are Sales and Lettings department, and each has a numeric system denoting the property's status.

I have tried to use if functions to query the department and status of each property, and to return a different text string for each status, but all of the properties are marked as 'On hold' (i.e. the first option)

The code is as follows. It's not particularly elegant, apologies.

function prop_status( $dept = null, $availability = null) {
if ( $dept = "Lettings" and $availability = "1") {
  return "On hold";
}
if ( $dept = "Lettings" and $availability = "2") {
  return "For rent";
}
if ( $dept = "Lettings" and $availability = "3") {
  return "References pending";
}
if ( $dept = "Lettings" and $availability = "4") {
  return "Let agreed";
}
if ( $dept = "Lettings" and $availability = "5") {
  return "Let";
}
if ( $dept = "Sales" and $availability = "1") {
  return "On hold";
}
if ( $dept = "Sales" and $availability = "2") {
  return "For sale";
}
if ( $dept = "Sales" and $availability = "3") {
  return "Under offer";
}
if ( $dept = "Sales" and $availability = "4") {
  return "Sold STC";
}
if ( $dept = "Sales" and $availability = "5") {
  return "Sold";
}
if ( $dept = "Sales" and $availability = "7") {
  return "Withdrawn";
}

Any help on getting this working would be much appreciated.

Chris L
  • 109
  • 8

1 Answers1

0

You should change all = to ==

function prop_status( $dept = null, $availability = null) {
if ( $dept == "Lettings" and $availability == "1") {
  return "On hold";
}
if ( $dept == "Lettings" and $availability == "2") {
  return "For rent";
}
if ( $dept == "Lettings" and $availability == "3") {
  return "References pending";
}
if ( $dept == "Lettings" and $availability == "4") {
  return "Let agreed";
}
if ( $dept == "Lettings" and $availability == "5") {
  return "Let";
}
if ( $dept == "Sales" and $availability == "1") {
  return "On hold";
}
if ( $dept == "Sales" and $availability == "2") {
  return "For sale";
}
if ( $dept == "Sales" and $availability == "3") {
  return "Under offer";
}
if ( $dept == "Sales" and $availability == "4") {
  return "Sold STC";
}
if ( $dept == "Sales" and $availability == "5") {
  return "Sold";
}
if ( $dept == "Sales" and $availability == "7") {
  return "Withdrawn";
}

See comparison operators in php here

$a == $b Returns TRUE if $a is equal to $b

$a === $b Returns TRUE if $a is equal to $b, and they are of the same type.

CodeIt
  • 3,492
  • 3
  • 26
  • 37
  • Hero, thank you. Seems like an embarrassingly elemental mistake, oops.. – Chris L Jan 17 '18 at 15:49
  • @ChrisL Don't worry, Most programmer make the same mistake. Keep it my mind next time when you ask something in SO. BTW accept this as answer to your question for those coming from SEO. – CodeIt Jan 18 '18 at 13:28
  • just accepted your answer. Only just realised I had a notification. – Chris L Apr 11 '18 at 16:08