Closed. This question is off-topic。它目前不接受答案。
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
6年前关闭。
 <?php

$batchcourseid = $_POST['batchcourseid'];
$coursestatus = $_POST['coursestatus'];
$batchname = $_POST['batchname'];



$conn=mysql_connect("localhost","root","qwerty");
mysql_select_db("MIS");
$sql=("SELECT * from batch where CourseID = '$batchcourseid' AND BatchName LIKE '%$batchname%'");

$results = mysql_query($sql, $conn);

?>
<table width="1070" height="54" border="1">
  <tr>
    <td height="23">BatchID</td>
    <td>CourseID</td>
    <td>Batch Name</td>
    <td>Number Of Students</td>
    <td>Start Date</td>
    <td>End Date</td>
    </tr>
  <?php  while($row = mysql_fetch_array($results)) ?>
  <?php { ?>
  <tr>
    <td height="23"><?php echo $row['BatchID'] ?>&nbsp;</td>
    <td><?php echo $row['CourseID']; ?>&nbsp;</td>
    <td><?php echo $row['BatchName']; ?>&nbsp;</td>
    <td><?php echo $row['NumStud']; ?>&nbsp;</td>
    <td><?php echo $row['StartDate']; ?>&nbsp;</td>
    <td><?php echo $row['EndDate']; ?>&nbsp;</td>
    </tr>
    <?php } ?>

这段代码应该在表中给出一行,但它只是出现的空行。我做错了什么?
所有的列和文本也都存在。

最佳答案

%必须是LIKE字符串的一部分,因此它应该在'之间,而不是在它之前/之后:

BatchName LIKE '%$batchname%'"

关于php - php代码到while循环表仅返回空行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18288182/

10-12 20:15