- Edited
Segment.php
<?php
$mysqli = mysqli_connect("localhost","root","","squarellt");
$cid = required_param('id', PARAM_INT);
class segment
{
public function unitseg_set1()
{
$subject = $mysqli->query('SELECT * FROM order_subject WHERE id='.$cid.'');
while($row=$subject->fetch_array() )
{
echo '<div>'.$row['chem_name'].'</div>';
}
}
public function unitseg_set2()
{
$subject = $mysqli->query('SELECT * FROM order_subject WHERE id='.$cid.'');
while($row=$subject->fetch_array() )
{
echo '<div>'.$row['physiotherapy_nn'].'</div>';
}
}
public function unitseg_set3()
{
$subject = $mysqli->query('SELECT * FROM order_subject WHERE id='.$cid.'');
while($row=$subject->fetch_array() )
{
echo '<div>'.$row['commun_gg'].'</div>';
}
}
}
?>
home_segment.php
<?php
require_once('segment.php');
$acc = new segment();
$account1 = $acc->unitseg_set1();
$account2 = $acc->unitseg_set2();
$account3 = $acc->unitseg_set3();
echo $account1;
echo $account2;
echo $account3;
I was trying to pullout the content of all the functions defined from the class segment in segment.php. And calling all the three functions from a class segment in home_segment.php Is this a correct way of calling multiple functions from one class.
Or suggest with good OOP's concept. How could I improve the above similar functionality in Object Oriented Programming.
(MOD: added markdown for code blocks)