从mySQL中恢复特定记录并以html格式显示

时间:2016-12-21 11:56:47

标签: php mysql

我有一个充满记录的数据库,我想使用php从中检索数据并将其显示在html文件中。问题是我需要通过指定的client_id在html页面中一次显示一行。我是php和mySQl的新手,也是stackoverflow的新手,所以请理解。谢谢大家。

以下是我用来检索数据的两个函数。

queries.php
//Get all clients from the db.
function get_all_clients() {
require (ROOT_PATH."inc/database.php");
try {
    $results = $db->query("SELECT * FROM clients ORDER BY client_id ASC");
} catch (Exception $e) {
    echo "Error Code: 1046";
    exit;
}
$clients = $results->fetchall(PDO::FETCH_ASSOC);
return $clients;
}

//Get single client from the db.

function get_client_single() {
  require (ROOT_PATH."inc/database.php");
  try{
      $results = $db->prepare("SELECT * FROM clients
      WHERE client_id= ? ORDER BY client_id ASC");
      $results->bindParam("?", $client_id, PDO::PARAM_INT);
      $results->execute();
  }catch(Exception $e){
     echo "ERRROR";
     exit;
  }
    $client = $results->fetch(PDO::FETCH_ASSOC);

我应该采取的结果应该是:

index.php

<?php
require_once("inc/config.php");
include(ROOT_PATH . "inc/queries.php");
$allClients = get_all_clients();

$fName  = "John";
$lName  = "Pappas";
$gender = "Mr";

?>
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Blood Test Form</title>
</head>

<body>

<h1>Test Form</h1>
<p>
    Dear<?php echo " "."$gender" ." "."$fName" ." "."$lName" ." "?      >.
</p>

</body>

有关如何通过调用函数并显示用户询问的特定记录使其动态化的一些帮助。谢谢大家

0 个答案:

没有答案