我想在搜索文本框中搜索以逗号分隔的字符串。我尽了最大努力,但在查询时也将逗号作为字符串。我尽了最大努力,但在查询时也把逗号作为字符串。
Php代码:
<?php
$link = mysqli_connect("localhost", "root", "root123", "newdb");
// Check connection
if($link === false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
if(isset($_POST['search']))
{
$value=$_POST['search'];
$search= explode(',', $value);
//echo $value;
$sql="select * from qcdata where run_no = '$value[0]' or run_no ='$value[1]' or run_no = '$value[2]'";
echo $sql;
}
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
?>
<div id="table">
<table width="30%" height="10%" border="1" >
<tr >
<th>sno</th>
<th>project_id</th>
<th>file_name</th>
<th>total_bases</th>
<th>total_reads</th>
<th>bases_q20</th>
<th>bases_q30</th>
<th>average_read_length</th>
<th>readlength_range_min</th>
<th>readlength_range_max</th>
<th>gc_percentage</th>
<th>platform</th>
<th>run_no</th>
<th>creation_by</th>
<th>creation_date</th>
<th>last_modified</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td><?php echo $row['sno'] ;?> </td>
<td><?php echo $row['project_id'] ;?> </td>
<td><?php echo $row['file_name'] ;?> </td>
<td><?php echo $row['total_bases'] ;?> </td>
<td><?php echo $row['total_reads'] ;?> </td>
<td><?php echo $row['bases_q20'] ;?> </td>
<td><?php echo $row['bases_q30'] ;?> </td>
<td><?php echo $row['average_read_length'] ;?> </td>
<td><?php echo $row['readlength_range_min'] ;?> </td>
<td><?php echo $row['readlength_range_max'] ;?> </td>
<td><?php echo $row['gc_percentage'] ;?> </td>
<td><?php echo $row['platform'] ;?> </td>
<td><?php echo $row['run_no'] ;?> </td>
<td><?php echo $row['creation_by'] ;?> </td>
<td><?php echo $row['creation_date'] ;?> </td>
<td><?php echo $row['last_modified'] ;?> </td>
</tr>
</div>
<?php
}
// Close result set
mysqli_free_result($result);
}
else{
echo " No records matching your query were found.";
}
}
else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
</table>
答案 0 :(得分:0)
试试这个
$value=$_POST['search'];
$search= explode(',', $value);
$searchQry = "'" . implode("','", $search) . "'";
$sql="select * from qcdata where run_no in ($searchQry)";