I have this php code, framework yii2
public function getCourse($id) { $data = PriceType::find() ->select('course') ->from('price_type') ->where(['id' => $id]) ->one(); return $data->course; } In this method sql query, there is a loop
$data = PriceType::getCourse($model->price_type_id); if($model->price_type_id == 1) $model->price_usd = ($model->price*$data); elseif ($model->price_type_id == 2) $model->price_usd = ($model->price/$data); elseif ($model->price_type_id == 3) $model->price_usd = ($model->price/$data); elseif ($model->price_type_id == 4) $model->price_usd = ($model->price/$data); If the price_type_id value is equal to the id, then we perform such an operation.
if-elseif must be rewritten into one function. The code works, but you need to work regardless of the number of records in the database.
The database contains the courses and currency names. Those. if you need to add a field, you need to write again if ... How to do differently, according to the normal?
operandand let's say for type 1 assign it*, and for 2,3,4/and on this field it will be clear with what price what to do. All the cheese bor only in order to convert to local currency? - Makarenko_I_V$datais the exchange rate to the dollar, then standardize it, so that it indicates how much currency you can buy for one dollar, then always when setting the currency you will need to divide and, when received, multiply regardless of the currency. And also make a separate crown every 10min. will update courses. - Makarenko_I_V