PDO inquiry, if there is no wanted product, how do I search for other product

Hi,
PDO inquiry, if there is no wanted product, how do I search for other product
There are multiple product types

4IF+RF,
8IF+MDU+RF,
13IF+MDU+RF,
16IF+RF,
There may be two options, but not all options.
The first option takes precedence, if the first option is not available, look for the second option.

$multiswitch = array("8IF+MDU+RF","13IF+MDU+RF");

WHERE multiswitch.urun_stok =? AND transmittertipi.optik_transmitter_tipi =?

$multiswitch->execute(['1',$multiswitch]);

How should I do it?

Instead of using =? You might try LIKE instead. WHERE multiswitch.urun_stok LIKE “%?%”
This would select items similar to the typed in values. Otherwise, you have to do two selects, or more.
One for the exact requested items, second for the LIKE ones and a third just to take any items.

Really depends on what you are wanting the user to find.

This item shows stock => urun_stok

The user selects satellites at the beginning of the wizard.
1 Satellite = 4 IF
2 Satellite = 8 IF
3 Satellite = 12 IF
The logic here is:
User selected two satellites and The product with 8 IF inputs is required, so this is the 8IF+MDU+RF product
However, if the product with 8 IF entries is not available in stock, give the next product. So give this 13IF+MDU+RF product
Give a higher model if there is no targeted product

Well, that would probably require two queries. One to see if the correct one is available.
If it is not available ( In stock ) then run a second query to select the next one up.
You might need to repeat this moving up if they are not in stock.

To do that in one query would require a lot of logic and would be much easier to just do two queries.
You would just need to check the results of the first one and if zero results, run a second one.

Yes, it requires a few queries

switch([$secilen_uydu_sayisi, $mdu4uydusayisi]){
	case $secilen_uydu_sayisi == 2 && $mdu4uydusayisi == 1 : $hedefsecenek= array(
	"8IF+MDU+RF", "13IF+MDU+RF"); break;
	case $secilen_uydu_sayisi == 3 && $mdu4uydusayisi == 1 : $hedefsecenek= array(
	"8IF+MDU+RF", "13IF+MDU+RF"); break;
	case $secilen_uydu_sayisi == 4 && $mdu4uydusayisi == 1 : $hedefsecenek= array(
	"13IF+MDU+RF", "16IF+RF"); break;
	case $secilen_uydu_sayisi == 1 && $mdu4uydusayisi == 0 : $hedefsecenek= array(
	"4IF+RF", "8IF+MDU+RF"); break;
	case $secilen_uydu_sayisi == 2 && $mdu4uydusayisi == 0 : $hedefsecenek= array(
	"8IF+MDU+RF", "13IF+MDU+RF"); break;
	case $secilen_uydu_sayisi == 3 && $mdu4uydusayisi == 0 : $hedefsecenek= array(
	"13IF+MDU+RF", "16IF+RF"); break;
	case $secilen_uydu_sayisi == 4 && $mdu4uydusayisi == 0 : $hedefsecenek= array(
	"16IF+RF"); break;
}

The first option is what brand does this product come from? Create a brand array
The second option is to create a array of the IDs and types of stock available products.
The third option is to put what’s found with the for loop into the function

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, $analog_kanal_sayisi,
 $bulunan_modulator_idler=array($ids[$vartekli])
 ); 
break;
}
}

if (!isset($modulatorarray)) {stokyokgoster($marka, $analog_kanal_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, $analog_kanal_sayisi,
 $bulunan_modulator_idler=array($ids[$var3kaskad1], $ids[$var3kaskad2])
 );
	break;
}

These codes continue to increase
"8IF+MDU+RF", "13IF+MDU+RF", "8IF+MDU+RF-13IF+MDU+RF"
To give more than one product to the same option, I separate it with hyphens. The code above increases according to the option.

I create output tables within the function at the end of the scripts.

function modulatorvarsagoster($bulunan_toplam_cikis, $bulunan_marka, $analog_kanal_sayisi, $bulunan_modulator_idler) {
// My output codes are here
}

Actually, I used this code before but couldn’t think of using it here. :grinning: :grinning:

Thank you

Well, I did not help you much. Just made you think about it from a different viewpoint.
You did all the work.

Nice work! Glad you solved it!

I was using this code elsewhere but couldn’t think it would work here.
It came to my mind when you said that you need a few queries and it worked for me in more than one place.
Is the idea with software important? :grinning: :grinning:
Thank you

Sponsor our Newsletter | Privacy Policy | Terms of Service