显示多行mysql

时间:2016-06-10 02:35:29

标签: php

我现在正在执行搜索功能,即按ID搜索。 例如,有ID 791481,791431,791474。如果我输入791481,它可以在表格中显示记录。

现在我要输入7914,它能够显示所有具有以7914开头的ID的记录,包括(791481,791431,791474)。我该怎么办?

这是我的代码

function getByItem($conn){
	global $resArray;

	$id = $_GET["id"];

	//for a item id, we need
	//1. item info
	//2. lastest item in out record and related report
	//3. lastest item repair record 

	$query = "SELECT * FROM `item` WHERE item_id LIKE'".$id."%'";
	$result = mysqli_query($conn, $query);

	$resArray["status"] = "ok";
	if($result){
		if($result->num_rows > 0){
			$resArray["item"]=mysqli_fetch_assoc($result);
			}
		
		
	}else{
		$resArray["status"] = "fail";
	}

	$query = "SELECT * FROM (SELECT * FROM `inoutrecord`  WHERE item_id LIKE'".$id."%') AS I NATURAL JOIN `report` ORDER BY report_date DESC";
	$result = mysqli_query($conn, $query);
	//$resArray["echo1"] = $query;

	if($result){
		if($result->num_rows > 0){
			$resArray["inoutrecord"]=mysqli_fetch_assoc($result);
		}
	}else{
		$resArray["error"] = mysqli_errno($conn).":".mysqli_error($conn);
		$resArray["status"] = "fail";
	}


	$query = "SELECT * FROM `repairrecord` WHERE item_id LIKE'".$id."%' ORDER BY rr_date DESC";
	$result = mysqli_query($conn, $query);
	//$resArray["echo2"] = $query;


	if($result){
		if($result->num_rows > 0){
			$resArray["repairrecord"]=mysqli_fetch_assoc($result);
		}
	}else{
		$resArray["error"] = mysqli_errno($conn).":".mysqli_error($conn);
		$resArray["status"] = "fail";
	}

}

0 个答案:

没有答案