【问题标题】:How to parse the information from mysql database to html page using php如何使用php将mysql数据库中的信息解析到html页面
【发布时间】:2015-06-12 06:43:50
【问题描述】:

我创建了一个接受用户输入的 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();
?>  

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

帮我这样做,提前谢谢。

【问题讨论】:

  • 什么是ajax请求??
  • 我有一个数据库,我想用 php 连接到这个 HTML 页面。

标签: php html mysql sql


【解决方案1】:

删除这一行

$row = mysqli_fetch_assoc($result);

【讨论】:

  • 感谢您的回复,我也尝试删除该行,但它不起作用,我得到相同的输出,先生。
  • 在while循环中 print_r ($row);并检查你得到了什么
  • "Undefined index: Sample_name in /var/www/html/details.php on line 16" 我在 php 脚本中遇到这个错误,如何解决这个问题?
  • Sample_name 可能是小写字段 - sample_name
【解决方案2】:

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

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

尝试使用请求方法,而不是像get方法

$userinput = $_REQUEST['Sample_name'];

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    相关资源
    最近更新 更多