繁体   English   中英

如何使用php将信息从mysql数据库解析到html页面

[英]How to parse the information from mysql database to html page using php

我创建了一个HTML页面,该页面接受用户的输入,并且需要获取特定行的信息。

以下是保存在“ ProcessDetails.html”中的HTML代码

<form action="details.php" method="get"/>
<h3 align="center"><FONT color=#CCFF66>ENTER SAMPLE NAME</h3>
<p align="center"> 

<input type="text" id="Samplename" name="Sample_name"/>

</p>
<div style="text-align:center"> 
<button     type="submit" value="SEARCH">
   <img alt="ok" src=
   "http://www.blueprintcss.org/blueprint/plugins/buttons/icons/tick.png" /> 
   SEARCH
  </button>
</form>  

以下是另存为“ details.php”的php脚本

<?php
$userinput = $_GET['Sample_name'];
  $servername = "localhost";
$username = "root";
$password = "";
$dbname = "ProcessTrackingSystem";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}

$result = mysqli_query($conn, "SELECT * FROM ProcessDetails WHERE Sample_name = '$userinput'") or die(mysqli_error($conn));

$row = mysqli_fetch_assoc($result);



while ($row=mysqli_fetch_row($result))
{
printf ("%s (%s)\n",$row[0],$row[1]);
}



#printf ("SO_Number: %s \n",$row["SO_Number"])
#print_r($row);

printf ("SO_ID:->");
printf ($row['SO_ID']);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("No of samples:->");
printf ($row['No_of_samples']);
printf ("<br>\r\n");
printf ("<br>\r\n"); 

printf ("Sample name:->");
printf ($row['Sample_name']);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Client name:->");
printf ($row["Clientname"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Institution:->");
printf ($row["Institution"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Run number:->");
printf ($row["Runnumber"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Obtained reads:->");
printf ($row["Obtainedreads"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Rerun Info:->");
printf ($row["RerunInfo"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Total reads:->");
printf ($row["Totalreads"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Run date:->");
printf ($row["Rundate"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Raw data location:->");
printf ($row["Rawdatalocation"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Analyst:->");
printf ($row["Analyst"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Mentor:->");
printf ($row["Mentor"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Analysis start date:->");
printf ($row["Analysisstartdate"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Analysis end date->:");
printf ($row["Analysisenddate"]);
printf ("<br>\r\n");
printf ("<br>\r\n");

printf ("Report location->:");
printf ($row["Reportlocation"]);



mysqli_free_result($result);
$conn->close();
?>  

我需要基于“样品名称”行的表格格式的所有这些数据。 现在,它不会在新网页中显示任何输出。

预先感谢我的帮助。

删除此行

$row = mysqli_fetch_assoc($result);

在您的表单中尝试使用post方法将值发布到其他页面

<form action="details.php" id="searchForm" method="post">

尝试使用请求方法代替类似的get方法

$userinput = $_REQUEST['Sample_name'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM