V
V
VMorello2018-05-04 17:25:04
PHP
VMorello, 2018-05-04 17:25:04

How to fix a piece of PHP, JS code?

Good day! Please help me understand:
In a piece of code:

<?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 '<option value="'.$g[id].'" '.$sel.'>'.$g[name].' '.$g[currency].'</option>';
 }
   } else {
echo '<option>'.$lang[no_have_gateways].'</option>';
} 
?>


Essence of the question:
There are several IDs in the database (for example, 10)
They are all unloaded with one command (As I understand it) this
"echo '<option value="'.$g[id].'" '.$sel.'>'.$g[name].' '.$g[currency].'</option>';"


It is necessary to make it so that I could put a value from its list, for example, to ID 5. "style="color:red""

As I see it -
"'<option value="'.$g[5].'" '.$sel.' style="color:red">'.$g[name].' '.$g[currency].'</option>';"

But this is not correct, or I don’t know how to add this line correctly so that all 10 positions are displayed, but the position that has ID 5 in the database was red

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-05-04
@webinar

They are all unloaded with one command (As I understand it) this

no. This line prints data from variables. It has nothing to do with the database.
Your decision:
$style = "color: green;"; //загоняем в переменную то что нам надо
if($g[id] == 5){
    $style = "color: red;"; //загоняем в переменную то что нам надо, но только если $g[id] == 5
}
echo '<option value="'.$g[id].'" '.$sel.'  style="'.$style.'">'.$g[name].' '.$g[currency].'</option>'; //подставляем переменную туда куда заблагорассудится

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question