mysql - sql/php to grab the minimum & maximum from multiple table entries -
i hope below makes sense...
i'm grabbing of children records using following (another script getchildrecords):
<?php $children = $this->item->getchildrecords(); ?>
i doing foreach grab of children house id's:
<?php foreach ( $children $i => $id ) { $house = jtable::getinstance('house', 'mytable'); $house->load($id); ?>
then pulling number of rooms each child house entry:
<div><?php $house->rooms; ?></div>
and finishing off foreach:
<?php } ?>
the children table may contain following room entries:
id - 22 rooms - 1 | id - 22 rooms - 5 | id - 22 rooms - 2 | id - 22 rooms - 3
question:
what want show min max number of rooms of child entries.
i.e. 1-5
do need single children entries on page? or overview? if don't need single entries create function
public function getminandmaxrooms() { $con=mysqli_connect("localhost","my_user","my_password","my_db"); $result mysqli_query($con,"select id, min(rooms), max(rooms) rooms group id"); if ($result !== false) { return $result->fetch_all(mysqli_num); } return array(); }
and in template cycle through it:
<?php foreach ($this->item->getchildrecords() $child) : ?> <?php echo $child[0) . ': ' . $child[1] . '-' - $child[2] ?> <?php endforeach; ?>
Comments
Post a Comment