Work with selected in php where the error and how to fix it?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 views
Good day! Please help to understand:
Here's a piece of code from selected1:
<?php$gateways = $db->query("SELECT * FROM bit_gateways WHERE allow_receive='1' and status='1' ORDER BY id"); if($gateways->num_rows>0) { while($g = $gateways->fetch_assoc()) { if($g['default_receive'] == "1") { $sel = 'selected'; } else { $sel = "; } echo ''.$g[name].' '.$g[currency].''; } } else { echo ''.$lang[no_have_gateways].''; } ?>


What I want to do:
In the database there are multiple ID (e.g. 10)
The display is shown with a single line
echo ''.$g[name].' '.$g[currency].''


We need to do when select list of select1 with ID 5,6,7-for example to put the value of data-select-options="1,2,3,4,8,9" then in select2 should show only ID I have specified in the data-select-options="

PS Just tell me how to register it value for example
if($g['id'] == "5"){//if the id is 5 adding data-select-options echo ''.$g[name].' '.$g[currency].''; }

or
if($g['id'] == "5") { $select= 'data-select-options="1,2,3,4,8,9"'; } else { $select= "; }

Thanks for the answer from the next question. But I don't know how to use them.... how to use them in your code. please help

Tell me how to solve it! I will be grateful!

UPD.... Solution for 1 ID like to add a few more ID?
<?php $gateways = $db->query("SELECT * FROM bit_gateways WHERE allow_send='1' and status='1' ORDER BY id"); if($gateways->num_rows>0) { while($g = $gateways->fetch_assoc()) { if($g['default_send'] == "1") { $sel = 'selected'; } else { $sel = "; } if($g['id'] == "1") { $usd = 'data-select-options="5,6,7,8,9,10"'; } else { $usd = 'data-select-options="1,2,3,4,5,6,7,8,9,10"'; } echo ''.$g[name].' '.$g[currency].'';} } else { echo ''.$lang[no_have_gateways].'';} ?>


I tried if($g['id'] == "1,2,3") - not working.
by | 10 views

1 Answer

0 like 0 dislike
You can do this:
In the beginning, to add an array (ID=>what-should-substitute) with all the possible options

$arDataSelectOptions = [ 1 => 'data-select-options="5,6,7,8,9,10"', 5 => 'data-select-options="3,5,7"', 10 => 'data-select-options="8,9,10"', ... 'default' => 'data-select-options="1,2,3,4,5,6,7,8,9,10"' ];


And then the line
if($g['id'] == "1") { $usd = 'data-select-options="5,6,7,8,9,10"'; } else { $usd = 'data-select-options="1,2,3,4,5,6,7,8,9,10"'; }

replace
if(isset($arDataSelectOptions[intval($g['id'])])) $usd = $arDataSelectOptions[intval($g['id'])]; else $usd = $arDataSelectOptions['default'];
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
3 answers
110,608 questions
257,187 answers
0 comments
40,796 users