Skip to content
Advertisement

How to check if all mysql results are equal

I’m facing a difficulty at the moment – I’m working on a real-estate website where the seller has some developments which have individual units within each development (a house with 4 apartments, for example).

The development has a status column in the database which specifies if it is Available, Reserved or Sold whereas each unit also has the same columns in their table.

The problem I’m trying to tackle is that developments still appear as Available even if all units are marked as Sold – of course the sellers can change this on their own but many times don’t.

I want to make a script (which eventually will be used as a cron job) to check all development units statuses and change the development’s status to Reserved if all units are set to Reserved, for example.

I wrote the following code to echo all properties and their respective units using a units foreach inside a developments foreach

JavaScript

The thing is I’d need to check if all unit statuses from a single development are the same because in case they were, I’d want to change the status of the development to the one which all units have.

So in this case I’d like to be able to see through PHP if all units have the status have the same value by using the $unit[‘status’] value or something.

Does anyone have an insight on how I could do this? I just need to know what method I can use to verify if all units results have the same value in the status column.

It doesn’t need to be in PHP if there is a better way somehow through a query or something.

Advertisement

Answer

Big thanks to @Salman A for his helpful take on how the query should look like,

I managed to use that to later on apply the status of a development’s units to the development’s status itself,

Thank everyone for your valuable takes,

JavaScript

Cheers

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement