I'd like your suggestion about the switch

Hello,
There are products with a certain number of outputs
On-demand product search also selects the next option when out of stock
Sample:
If the product with 16 output is not available in stock, it moves to the next option.
“16”, “8-8” as

The following switch code is in the php file
I want to import this to the admin panel so that the admin options can be edited when needed

How should I do this?
I request your suggestion

switch($daire_sayisi){ 
case $daire_sayisi <= 8 : $hedefsecenek= array(
"8",
"12"); break;
case $daire_sayisi <= 12 : $hedefsecenek= array(
"12",
"16", "8-8"); break;
case $daire_sayisi <= 16 : $hedefsecenek= array(
"16", "8-8",
"20", "12-8"); break;
case $daire_sayisi <= 20 : $hedefsecenek= array(
"20", "12-8",
"24", "12-12", "16-8", "8-8-8"); break;
case $daire_sayisi <= 24 : $hedefsecenek= array(
"24", "12-12", "16-8", "8-8-8",
"20-8", "16-12", "12-8-8"); break;
case $daire_sayisi <= 28 : $hedefsecenek= array(
"20-8", "16-12", "16-8-8",
"32", "24-8", "20-12", "16-16", "16-8-8", "12-12-8", "8-8-8-8"); break;
case $daire_sayisi <= 32 : $hedefsecenek= array(
"32", "24-8", "20-12", "16-16", "16-8-8", "12-12-8", "8-8-8-8",
"24-12", "20-16", "20-8-8", "16-12-8", "12-12-12", "12-8-8-8"); break;
case $daire_sayisi <= 36 : $hedefsecenek= array(
"24-12", "20-16", "20-8-8", "16-12-8", "12-12-12", "12-8-8-8",
"32-8", "24-16", "20-20", "24-8-8", "20-12-8", "16-16-8", "16-8-8-8", "12-12-8-8", "8-8-8-8-8"); break;
case $daire_sayisi <= 40 : $hedefsecenek= array(
"40","32-8", "24-16", "20-20", "24-8-8", "20-12-8", "16-16-8", "16-8-8-8", "12-12-8-8", "8-8-8-8-8",
"32-12", "24-20", "24-12-8", "20-16-8", "16-16-12", "12-12-

continues…

A switch/case statement is used when you want to select between different PROCECSSING to perform, not different data values. Data should be stored in a data structure, such as an array or a database table, then search that data structure to find the entry you want.

The switch($daire_sayisi){ part of that statement isn’t actually doing what you think. This is being treated as switch(true){ and is finding the first $daire_sayisi <= x comparison that is true.

To be able to edit this data, you would store the choices in a database table. You would then retrieve, edit, and update (or replace) the data using the admin panel. To search for the first entry that matches the current $daire_sayisi value, you would use an sql query, then fetch the resulting data into the $hedefsecenek array. The table would have columns for - a primary autoincrement id column for referencing any row of data, a secondary index for the daire_sayisi column, then the data column. There would be one row for each data value for each daire_sayisi value, e.g. for daire_sayisi <= 16, there would be 4 rows for the data that you have shown.

I created a table like below


DROP TABLE IF EXISTS `algoritma`;
CREATE TABLE IF NOT EXISTS `algoritma` (
  `daire_sayisi` int NOT NULL,
  `hedefsecenek` longtext NOT NULL,
  UNIQUE KEY `daire_sayisi` (`daire_sayisi`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb3;

--
-- Tablo döküm verisi `algoritma`
--

INSERT INTO `algoritma` (`daire_sayisi`, `hedefsecenek`) VALUES
(8, '8,12'),
(12, '12,16,8-8'),
(16, '16,8-8,20,12-8');

Sample
I will use this data later in the codes below

for ($vi = 0; $vi < count($hedefsecenek); $vi++) {
$hsecs = explode("-", $hedefsecenek[$vi]);
$hsecsay = count($hsecs);

if ($hsecsay == 1){ 
$vartekli = array_search($hsecs[0], $modulatorarray);
if ($vartekli !== false) {
modulatorvarsagoster( 
 $bulunan_toplam_cikis = array($hsecs[0]),
 $bulunan_marka=$marka, $qam_paket_sayisi,
 $bulunan_modulator_idler=array($ids[$vartekli])
 ); 
break;
}
}

if (!isset($modulatorarray)) {stokyokgoster($marka, $qam_paket_sayisi); continue 2;}
if ($hsecsay == 2){
$var3kaskad1 = array_search($hsecs[0], $modulatorarray);
$var3kaskad2 = array_search($hsecs[1], $modulatorarray);
if (($var3kaskad1 !== false) && ($var3kaskad2 !== false)) {
 modulatorvarsagoster(
 $bulunan_toplam_cikis = array($hsecs[0],$hsecs[1]),
 $bulunan_marka=$marka, $qam_paket_sayisi,
 $bulunan_modulator_idler=array($ids[$var3kaskad1], $ids[$var3kaskad2])
 );
	break;
}
$var3kaskad1 = array_search($hsecs[1], $modulatorarray);
$var3kaskad2 = array_search($hsecs[0], $modulatorarray);
if (($var3kaskad1 !== false) && ($var3kaskad2 !== false)) {
 modulatorvarsagoster(
 $bulunan_toplam_cikis = array($hsecs[0],$hsecs[1]),
 $bulunan_marka=$marka, $qam_paket_sayisi,
 $bulunan_modulator_idler=array($ids[$var3kaskad1], $ids[$var3kaskad2])
 );
	break;
}
}

.....
.........
.......

The edit screen is as follows
Ekran görüntüsü 2022-07-22 150325

I will add option to add new line with “Add Line” button

Did I understand what you said correctly?

Sponsor our Newsletter | Privacy Policy | Terms of Service