sbayrak
asked on
if all rows found are equal to each other
How can we use if statement inside the foreach loop below to check whether all the row values (no matter what their count is) returned by the mysql query are equal to each other?
$query = "SELECT field_qty_item FROM ...";
foreach ($query as $row) {
if all $row values returned are equal to each other...
// do smthng
}
else {
// do nothing... or do another thing...
}
$query = "SELECT field_qty_item FROM ...";
foreach ($query as $row) {
if all $row values returned are equal to each other...
// do smthng
}
else {
// do nothing... or do another thing...
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What exactly are you trying to achieve. Maybe the IF statement isn't the best way forward.
You can have a GROUP BY clause in your SQL Statement:
You can have a GROUP BY clause in your SQL Statement:
SELECT count(field_qty_item) as Amount, field_qty_item FROM yourTable GROUP BY field_qty_item
You would then only get unique values of field_qty_item, along with an Amount of how many times each value exists in the database. If you only get 1 record returned then clearly all the rows match each other.
ASKER
smooth
Open in new window