How to make a generic function to search for products?

There is a table stock and Columns
  • stock_id
  • stock_name
  • stock_imei
  • stock_category


In this table store the list of products that have different stock_category

If stock_category the value of the phone in stock_imei recorded data but if headphones that stock_imei empty.

Also there is a function which makes searching for these products and displays their values

He brings to the table and depending on stock_category displays the structure of the table, and here in this moment and I am having a problem.

Here for example I gave a few columns for convenience, but the original number of columns and values stock_category not limited

At the moment I'm doing the test if { .. }

if($stock_caregory == 'car') {
 echo 'stock_id' ... 
 echo 'stcok_name' ... //in most categories have a name but there is no imei in the sky
 echo 'imei' ... 
//then derive that relate to the car 
} 

if($stock_caregory == 'sky') { 
 echo "stock_id"
 echo 'stock_name'
}

If for example 100 or 1000 categories all write in if not reasonable

Can I make one universal function that will, depending on the category, display data ?

How can I do that ?

At the moment I understand that the architecture and logic is not correct on this please advise me how best to implement it.
April 19th 20 at 12:33
0 answer

Find more questions by tags MySQLPHP