Reusable SELECT from any table and fields

Codes here !

Moderators: egami, macek, gesf

Post Reply
aldo151
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Mar 01, 2021 1:43 pm

Mon Mar 01, 2021 1:59 pm

Hi there, wanted to see how I would have the columns I specified in

Code: Select all

$fields = array('id','type'); 
then be generated dynamically in the while loop and any other field I state in

Code: Select all

$fields = array('id','type');
then its added to the while loop in the below

Code: Select all

include('db.php');

class SelectData{


public function wpquery_select($conn,$sql,$fields){

$results = $conn->query($sql);

if($results->num_rows > 0){

	while($row = $results->fetch_assoc()){
		
		// How would you process the array $fields which holds all the rows specified and dynamically create echo $row['id'], $row['id'] and so on?
		
	}
	
  }

$conn->close();

 }

	
}



$select = new SelectData();

$sql = "SELECT * FROM orders";


$fields = array('id','type');


$select->wpquery_select($conn,$sql,$fields);
Post Reply