Как заполнить эту таблицу HTML, используя PHP и MySQL

Обновленный ответ, работающий над Swift 3

    extension String {
        init?(htmlEncodedString: String) {
            let encodedData = htmlEncodedString.data(using: String.Encoding.utf8)!
            let attributedOptions = [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType]

            guard let attributedString = try? NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) else {
                return nil
           }
            self.init(attributedString.string)
}
0
задан Tanner B 5 March 2019 в 00:43
поделиться

2 ответа

  <table>
<tr>
    <th>Id</th>
    <th>Name</th>
    <th>Serial</th>
</tr>

<?php


$servername = "localhost";
$username = "";
$password = "";
$dbname = "verify";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$result = $conn->query($sql);

$stack = array();

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        array_push($stack, $row);
        if(!$array) {
            return $row;
        }
    }
}

$conn->close();




foreach($stack as $item)
{
    echo "<tr><td>" . $row['ProductId'] . "</td><td>" . $row['Name'] . "</td>.  <td>" . $row['SerialId'] . "</td></tr>";
}




?>

0
ответ дан Russ J 5 March 2019 в 00:43
поделиться
<?php
 $table='<table>
            <tr>
             <th>Id</th>
             <th>Name</th>
             <th>Serial</th>
           </tr>';


  $servername = "localhost";
  $username = "";
  $password = "";
  $dbname = "verify";

  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);

 // Check connection
 if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
  }

 $result = $conn->query($sql);

  $stack = array();

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    array_push($stack, $row);
    if(!$array) {
        return $row;
     }
 }
}

$conn->close();

 $table_content='';
 foreach($stack as $item)
 {
  $table_content.= "<tr>
                     <td>" . $row['ProductId'] . "</td>
                     <td>" . $row['Name'] . " </td>.  
                     <td>" . $row['SerialId'] . "</td>
                   </tr>";

 }
echo $table.$table_content.'</table>';
 ?>
0
ответ дан Premlatha 5 March 2019 в 00:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: