Please tell me, is there a code that outputs data from a table using a loop:

<?php $host = 'localhost'; $db = ''; $user = ''; $pass = ''; $charset = 'utf8'; $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO($dsn, $user, $pass, $opt); $stmt = $pdo->query("SELECT * FROM task WHERE id_t = ".$_GET['id'].""); while ($row = $stmt->fetch()) { echo "<div style='margin-left:77%;margin-top:2%;border-radius:10px;color:#777777;width:300px;height:auto;background:#fff;display: inline-block;'> <center><p style='font-weight:bold;font-size:20px;margin-top:10px;padding-bottom:10px;border-bottom:1px solid #e0e0e0;'>Информация о процессе</p></center> <table style='margin-top: -10px;margin-left:10px;'> <tr> <td style='font-size: 16px;color: #393939;padding-right:25px;padding-bottom:10px;'>Номер процесса:</td> <td style='font-size: 16px;color: #393939;padding-bottom:10px;'>".$row['id_t']."</td> </tr> <tr> <td style='font-size: 16px;color: #393939;padding-right:25px;padding-bottom:10px;'>Процесс:</td> <td style='font-size: 16px;color: #393939;padding-bottom:10px;'>".$row['process_t']."</td> </tr> <tr> <td style='font-size: 16px;color: #393939;padding-right:25px;padding-bottom:10px;'>Статус:</td> <td style='font-size: 16px;color: #393939;padding-bottom:10px;'><input style='width:100px;height:auto;border:0px;font-size:16px;color: #393939;' type='text' value='".$row['status_t']."'></td> </tr> <tr> <td style='font-size: 16px;color: #393939;padding-right:25px;padding-bottom:10px;'>Клиент:</td>"; } ?> 

How to output data without a loop?

  • And from us the question - why? - u_mulder Nov.
  • @u_mulder I think if we display the data for only one record it will be more correct, but this is not accurate) - Vladislav Samokhin
  • one
    Well, just call fetch once : $row = $stmt->fetch(); - u_mulder Nov.
  • @u_mulder good, thanks. - Vladislav Samokhin Nov.

0