html - Is there an easier way to call booleans from php? -


i trying call tinyint server while converting boolean.

is there easier way using?

while ($row = mysql_fetch_array($result)) {     echo "<td>",          "<input type=\"checkbox\" id='switch-state' name=\"$row[name]\" state=\"<script boolean(<? echo '$row[state]'; ?>) </script>\" </td>"; } 

this kinds of wrong.

  • you can't put <script> tag inside html attribute. horrible.
  • you can't have multiple html elements same id. when in loop, use counter generate unique ids.
  • you should pass string data output html through htmlspecialchars() avoid breaking result html , minimize risk of xss vulnerabilities.
  • you might want use other non-standard attributes (such state="…") transport data in element. html5's data-* attributes fit (data-state="…"). option css class, example. depends on intend state information.
  • javascript can handle numbers fine. when used in boolean context, 0 evaluates false, other numbers evaluate true. might want transport server data is, instead of translating it.

here's do.

$index = 0; while ($row = mysql_fetch_array($result)) {     $index++;     echo "<td>",         "<input type='checkbox' ",              "id='switch-state-$index' ",             "name='".htmlspecialchars($row['name'])."' ",             "data-state='".$row['state']}."'",         "></td>\n"; } 

which outputs:

<td><input type='checkbox' id='switch-state-1' name='foo' data-state='1'></td> <td><input type='checkbox' id='switch-state-2' name='bar' data-state='0'></td> 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -