In the row of the table I need to set two parameters: data-id and data-name , the data-name works for me in the code. But the data-id parameter can not be determined. Tell me please.

 <div class="ok"> <? $translates = [ 'id' => 'Id', 'oblastnazn' => 'Область назначения', 'proizvoditel' => 'Производитель', 'name1' => 'Наименование', 'categ' => 'Категория', 'tsokol' => 'Цоколь', 'sklad' => 'Наличие на складе', 'svetpotok' => 'Световой поток', 'colorsveh' => 'Цвет свечения' ]; $fields = array_keys($translates); $s = "SELECT %s FROM table"; $sql = sprintf($s, implode(',', $fields)); /** @var PDOStatement $stmt */ $stmt = $dbh->query($sql); $stmt->setFetchMode(\PDO::FETCH_ASSOC); while ($row = $stmt->fetch()) { foreach ($translates as $field=>$name) { print "<div class='tab'>"; print "<table>"; print "<thead>"; print "<tr>"; print "<th style='width: 180px; height: 50px;'><center>$name</center></th>"; print "</tr>"; print "</thead>"; echo "<br>"; print "<tr >"; print "<td class='chenge' style='width: 180px; height: 50px;' data-id='' data-name='$field' >"; print $row[$field]; print "</td></tr></table></div>"; } } ?> </div> 
  • And the problem is not accidentally in print "<td class='chenge' style='width: 180px; height: 50px;' data-id='' data-name='$field' >"; print "<td class='chenge' style='width: 180px; height: 50px;' data-id='' data-name='$field' >"; ? Apparently the data-id empty. - MikielD.
  • @MikielD, so I tried different options and I didn’t see the information I needed, so I ask for help. And the value is empty, I specifically left it. - Eliot
  • one
    So how do you think we understand why it is empty, if you don’t print anything in it anyway? What property do you write in the data-id? - u_mulder
  • @u_mulder, already found the answer. - Eliot
  • separate mapping and logic, do not force the brain to people who see your code habrahabr.ru/post/150267 , habrahabr.ru/post/31270 - apelsinka223

1 answer 1

I solved my problem, so that the data-id displays the parameter, you need to write like this

 "<td class='chenge' style='width: 180px; height: 50px;' data-id='$row[id]' data-name='$field' >";