从特定列中检索特定数据

时间:2017-06-13 02:42:11

标签: php mysql

我尝试将数据插入合规性表,名为受审核方的列,这不是主键。

所以数据录入后。我想根据" auditee"

检索数据

我应该将数据插入MySQL中的多个表(合规表和auditee_details表)还是任何想法?

<?php
// Create connection
$con=mysqli_connect("localhost","root","","mtt_iem");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$a = $_POST['date'];
$b = $_POST['block'];
$c = $_POST['module'];
$d = $_POST['auditor'];
$e = $_POST['sw_score'];
$f = $_POST['sw_comment'];
$g = $_POST['dm_score'];
$h = $_POST['dm_comment'];
$i = $_POST['uniform_score'];
$j = $_POST['uniform_comment'];
$k = $_POST['totalscore'];
$l = $_POST['auditorcomment'];
$m = $_POST['auditee'];

$sql = "INSERT INTO compliance_module 



(date,block,module,auditor,sw_score,sw_comment,dm_score,dm_comment,uniform_score,uniform_comment,totalscore,auditorcomment,auditee) ".

"VALUES ('$a','$b','$c','$d','$e','$f','$g','$h','$i','$j','$k','$l','$m')";

$result = mysqli_query($con,$sql);
?>

1 个答案:

答案 0 :(得分:0)

如果您想存储有关受审核方的其他信息,并且一个受审核方可以有多个compliance_modules,那么您可能希望创建一个带有auditee_id的单独的受审计方表,并使用compliance_modules表上的audite_id字段来引用哪个auditee_id您属于。

如果该表将有大量记录,并且您将通过受审核方查找模块,您将需要在该值上创建索引,这将使搜索量级更快:

CREATE INDEX compliance_modules_auditee_id ON compliance_modules(auditee_id)

然后你可以做

SELECT * FROM compliance_modules WHERE auditee_id = 'foo'