Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

What I have tried:

segment.php
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;
Posted
Updated 26-Jun-18 21:48pm
v3
Comments
Richard MacCutchan 27-Jun-18 3:47am    
That looks fine to me; is there a problem with running the code?
Member 13888866 27-Jun-18 4:10am    
Thank You for the comment. I couldn't print $account1; $account2; $account3;Is there a way of writing my code in OOPs concept. Would appreciate your support.
Richard MacCutchan 27-Jun-18 4:14am    
Your code is already using OOP concepts in the use of classes and objects. However your functions are not returning any results so there is nothing to display. See PHP: Returning values - Manual[^].
Member 13888866 27-Jun-18 4:16am    
Since I was just displaying the database records from each function. Is this a problem of just dispalying the content, rather passing an argument is mandatory.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900