Hello I'm getting results in format
location1 2 4
location2 3 2
location3 0 0
location1 1 0
How can I trim results so that row returning 0 and 0 is not displayed ? thank you
.................
Here is Mysql query, I don't know how to trim it from MySQL so I thought using PHP ..
SELECT hotelas.name, hotelas.address, hotelas.city, hotelas.country, hotelas.hotel_id
AS hotelid,
COUNT( DISTINCT apart.apartman_id ) AS number_of_free_ap,
COUNT( DISTINCT room.apartman_id ) AS num_of_free_rooms
FROM hotel AS hotelas
LEFT JOIN apartman AS apart ON ( apart.apartman_hotel = hotelas.hotel_id
AND apart.occupied =0
AND apart.what =1 )
LEFT JOIN apartman AS room ON ( room.apartman_hotel = hotelas.hotel_id
AND room.occupied =0
AND room.what =0 )
GROUP BY hotelas.hotel_id
TABLE field what, 0 - for room, 1 - apartment
So I get a few columns among which the most important ones are count columns , free rooms and free apartments. So I have a test hotel which is full 0 rooms and 0 apartments and I want is removed from this list where all other hotels have at least one room or one apartment available.
if you are querying you database to get this information and you can change the query, that would be the best place for it.
SELECT *
FROM myTable
WHERE
firstColumn != 0
OR
secondColumn != 0
If you are getting this in PHP from some other source (CSV or something), or you don't have control over the query, use array_filter()
:
// i'm assuming each line in your example is an array of values
$myArray = array_filter($myArray, 'noDoubleZeroes');
function noDoubleZeroes($line) {
return $line[1] != 0 || $line[2] != 0;
}
select * from table
where column1 !=0
or column2 !=0
That's how you can trim it in MySQL.
OTOH, if you have an array such as this ( you will usually get this after you query from a db)
array(array('location1', 2, 4), array('location2', 3, 2))
Then you need to loop over the array and do the manual filtering:
$newarrs=array();
foreach($arrs as $values)
{
if($values[1]!=0 || $values[2]!=0)
$newarrs[]=$values;
}
return $newarrs;
If i understood you correctly this should help
$columns = explode($resultLine, " ");
$whatYouWant = $columns[0];