Php 查询未运行
我想知道是否有人能发现这里出了什么问题?第一个查询已经过测试,并且正在运行,因为我可以打印$groups数组,但是第二个查询不会运行。当我硬编码$groups数组时,它运行良好Php 查询未运行,php,sql,Php,Sql,我想知道是否有人能发现这里出了什么问题?第一个查询已经过测试,并且正在运行,因为我可以打印$groups数组,但是第二个查询不会运行。当我硬编码$groups数组时,它运行良好 require ('mysqli_connect.php'); // Connect to the db. echo '<p>If no record is shown, this is because you had an incorrect or missing entry in the search f
require ('mysqli_connect.php'); // Connect to the db.
echo '<p>If no record is shown, this is because you had an incorrect or missing entry in the search form.<br>Click the back button on the browser and try again</p>';
//Coming from another page
$uninum=$_POST['uninum'];
$sname=$_POST['sname'];
$groups = array ( );
$count = count ($groups);
$q1 = "SELECT `groupid` FROM `groups`
WHERE `uninum` = '".$uninum."'";
$result1 = @mysqli_query($dbcon,$q1);
while ($row1 = mysqli_fetch_array ($result1, MYSQLI_ASSOC)){
$groups[] = $row1['groupid'];
}
for ($i = 0; $i < $count; $i++){
$q = "SELECT participants.sname, participants.uninum,
groups.groupid
FROM participants
INNER JOIN groups ON
participants.uninum = groups.uninum
WHERE groups.groupid ='".$groups[$i]."'";
$result = @mysqli_query ($dbcon, $q); // Run the query.
if ($result) { // If it ran, display the records.
// Table header.
echo '<table>
<tr>
<td><b>Edit</b></td>
<td><b>Surnname</b></td>
<td><b>University ID</b></td>
<td><b>Group</b></td>
</tr>';
// Fetch and display the records:
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<tr>
<td><a href="edit_group_member.php?uninum=' . $row['uninum'] . '">Edit</a></td>
<td>' . $row['sname'] . '</td>
<td>' . $row['uninum'] . '</td>
<td>' . $row['groupid'] . '</td>
</tr>';
}
echo '</table>'; // Close the table.
mysqli_free_result ($result); // Free up the resources.
echo "<br><br>";
} else { // If it did not run OK.
// Public message:
echo '<p class="error">The current users could not be retrieved. We apologize for any inconvenience.</p>';
// Debugging message:
echo '<p>' . mysqli_error($dbcon) . '<br><br>Query: ' . $q . '</p>';
}
}
require('mysqli_connect.php');//连接到数据库。
echo'如果未显示任何记录,这是因为搜索表单中的条目不正确或丢失。
单击浏览器上的“上一步”按钮,然后重试。;
//来自另一页
$uninum=$_POST['uninum'];
$sname=$_POST['sname'];
$groups=array();
$count=计数($groups);
$q1=“从“组”中选择“组ID”
其中'uninum`='“$uninum.”;
$result1=@mysqli_查询($dbcon,$q1);
而($row1=mysqli\u fetch\u数组($result1,mysqli\u ASSOC)){
$groups[]=$row1['groupid'];
}
对于($i=0;$i<$count;$i++){
$q=“选择participants.sname、participants.uninum、,
groups.groupid
来自参与者
上的内部联接组
participants.uninum=groups.uninum
其中groups.groupid='“$groups[$i]。”;
$result=@mysqli_query($dbcon,$q);//运行查询。
如果($result){//如果它运行,则显示记录。
//表格标题。
回声'
编辑
苏尔纳姆
大学ID
团体
';
//获取并显示记录:
而($row=mysqli\u fetch\u数组($result,mysqli\u ASSOC)){
回声'
“.$row['sname']”
“.$row['uninum']”
“.$row['groupid']”
';
}
echo“”;//关闭表。
mysqli_free_result($result);//释放资源。
回声“
”;
}否则{//如果它没有运行,则为OK。
//公开信息:
echo“无法检索当前用户。对于由此带来的不便,我们深表歉意。
”;
//调试消息:
回显“”.mysqli_错误($dbcon)。“
查询:”.$q.”;
}
}
$count始终等于零
$count始终等于零
$count始终等于零
$count始终等于零尝试使用
mysqli_query
删除@
,并且$groups
数组将不会开始循环,直到您的计数大于零。
如果您var\u dump($count)
它将返回零
$count = count ($groups);
var_dump($count);
您应该在查询
返回结果集后的计数
数组,就在结束while循环
$q1 = "SELECT `groupid` FROM `groups` WHERE `uninum` = '".$uninum."'";
$result1 = @mysqli_query($dbcon,$q1);
while ($row1 = mysqli_fetch_array ($result1, MYSQLI_ASSOC)){
$groups[] = $row1['groupid'];
}
// count here
$count = count ($groups);
尝试使用
mysqli_query
删除@
,同时$groups
数组将不会开始循环,直到您的计数大于零。
如果您var\u dump($count)
它将返回零
$count = count ($groups);
var_dump($count);
您应该在查询
返回结果集后的计数
数组,就在结束while循环
$q1 = "SELECT `groupid` FROM `groups` WHERE `uninum` = '".$uninum."'";
$result1 = @mysqli_query($dbcon,$q1);
while ($row1 = mysqli_fetch_array ($result1, MYSQLI_ASSOC)){
$groups[] = $row1['groupid'];
}
// count here
$count = count ($groups);
尝试使用
mysqli_query
删除@
,同时$groups
数组将不会开始循环,直到您的计数大于零。
如果您var\u dump($count)
它将返回零
$count = count ($groups);
var_dump($count);
您应该在查询
返回结果集后的计数
数组,就在结束while循环
$q1 = "SELECT `groupid` FROM `groups` WHERE `uninum` = '".$uninum."'";
$result1 = @mysqli_query($dbcon,$q1);
while ($row1 = mysqli_fetch_array ($result1, MYSQLI_ASSOC)){
$groups[] = $row1['groupid'];
}
// count here
$count = count ($groups);
尝试使用
mysqli_query
删除@
,同时$groups
数组将不会开始循环,直到您的计数大于零。
如果您var\u dump($count)
它将返回零
$count = count ($groups);
var_dump($count);
您应该在查询
返回结果集后的计数
数组,就在结束while循环
$q1 = "SELECT `groupid` FROM `groups` WHERE `uninum` = '".$uninum."'";
$result1 = @mysqli_query($dbcon,$q1);
while ($row1 = mysqli_fetch_array ($result1, MYSQLI_ASSOC)){
$groups[] = $row1['groupid'];
}
// count here
$count = count ($groups);
我的猜测是,如果删除
@
,您将看到错误。如果没有,请在查询中添加错误检查,例如或die(mysqli\u error())
。或者您可以在当前的错误日志中找到问题。为什么要执行$count=count($groups)
在用值填充$groups
数组之前?您正在设置$count
->$count=count($groups)的值
在向循环中的数组添加任何值之前->而(…){$groups[]=$row1['groupid'];}
因此$count
将始终为0
,因此第二个循环将永远不会运行。ProTip:在函数之前不要使用@
符号。如果出现错误,您应该捕获并处理它,而不仅仅是忽略它。当您可以简单地为($i=0;$i@
操作时,不设置计数变量的另一个很好的原因是,如果删除@
,您将看到错误。如果没有,请添加错误检查,例如或die(mysqli_error())
添加到您的查询中。或者您可以在当前的错误日志中找到问题。在用值填充$groups
数组之前,为什么要执行$count=count($groups);
操作?您正在设置$count
->$count=count($groups)的值在向循环中的数组添加任何值之前->while(…){$groups[]=$row1['groupid'];}
so$count
将始终是0
,因此您的第二个循环将永远不会运行。ProTip:永远不要在函数之前使用@
符号。如果出现错误,您应该捕获并处理它,而不仅仅是忽略它。当您可以简单地对($i=0;$i操作时,不设置计数变量的另一个很好的原因($groups);$i++{
我猜如果你删除@
你会看到错误。如果没有,在你的查询中添加错误检查,比如或die(mysqli_error())
。或者你可以在你当前的错误日志中找到问题。你为什么要做$count=count($groups)
在用值填充$groups
数组之前?您正在设置$count
->$count=count($groups);
在向循环中的数组添加任何值之前->而(…){$groups[]=$row1['groupid'];}
因此$count
始终是0
,s