0
這是我的xml文件和我的php代碼。我想通過我的PHP表單中的文本框的名字進行搜索,並且我想顯示關於特定學生的所有信息,但問題是我的xpath無法正常工作。任何幫助xpath。php和xml使用搜索解析
<students>
<student>
<firstname>John</firstname>
<lasttname>Snow</lasttname>
<student_id>160600</student_id>
<gender>male</gender>
<dob>23-06-95</dob>
<age>21</age>
<email>[email protected]</email>
<mobilenumber>57675060</mobilenumber>
<address>Winter Fel</address>
<cohort>BSE15PT</cohort>
<programme>Software Engineering</programme>
<mode>PT</mode>
</student>
<student>
<firstname>meryl</firstname>
<lastname>Burton</lastname>
<student_id>150500</student_id>
<gender>female</gender>
<dob>26-07-95</dob>
<email>[email protected]</email>
<mobilenumber>57800603</mobilenumber>
<address>rose hill</address>
<cohort>BSE15AFT</cohort>
<programme>software engineering</programme>
<mode>ft</mode>
</student>
</students>
<?php
if(isset($_POST['search']))
{
$xml=simplexml_load_file("studentInstance.xml") or die("Error: Cannot Create Object");
$xpath = $xml;
//query the document
$name = $_POST['studentname'];
$query = $xpath->query("/students/student/[firstname = '$name']");
echo $query;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Searching</title>
</head>
<body>
<form method="POST" action="searchRecord.php">
<label>Enter Student Name</label>
<input type="text" name="studentname"><br>
<input type="submit" name="search" value="search">
</form>
</body>
</html>
我不知道,我的手機,但學生是我想也許你需要特定的索引/學生/學生[1] /姓名列表 –