我只想从我对学生所做的所有查询结果中获得随机密码。在我的情况下,我尝试生成,但它只向所有查询的学生(大约 45 名学生)返回 1 个生成的密码。我应该怎么做一个随机的。请帮助..这是我的代码
<?php
if(isset($_POST['generate'])){
$charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+';
$generated_pass = substr(str_shuffle($charset), 0, 12);
$generate = $_POST['generate'];
}
?>
<form method="post" action='enroll_student.php' name ='register'>
<?php
$yr = date("Y");
if ($result = $mysqli->query("SELECT
tbl_studentreg.studId,
tbl_studentreg.fname,
tbl_studentreg.lname,
tbl_studentreg.mname,
tbl_studentreg.dob,
tbl_studentreg.address,
tbl_department.departmentName,
tbl_studentreg.sy
FROM tbl_studentreg
Inner Join tbl_department ON tbl_studentreg.departmentId = tbl_department.departmentId WHERE tbl_studentreg.sy = '$yr' "))
{
if ($result->num_rows > 0)
{
echo "<table width= '1000'>";
echo "<tr><th>StudentID</th><th>Name</th><th>Date of Birth</th><th>Address</th><th>Department</th><th>School Year</th><th>Password</th></tr>";
while ($row = $result->fetch_object())
{
echo "<tr>";
echo "<td align='center'>" . $row->studId . "</td>";
echo "<td align='center'>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
echo "<td align='center'>".$row->dob."</td>";
echo "<td align='center'>" . $row->address. "</td>";
echo "<td align='center'>".$row->departmentName."</td>";
echo "<td align='center'>".$row->sy."</td>";
if(isset($generated_pass)) {
//how could i make this one generate random password for every students..?
for($i=0; $i <= $row->studId; $i++){
echo "<td>$generated_pass</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No Results.";
}
}
else
{
echo "Error: " . $mysqli->error;
}
$mysqli->close();
echo '<br>';
include 'count.php'; //this one will give the total no. of results, just ignore.
?>
<br />
<tr><td></td></tr><tr><td><input type='submit' name='generate' value='Generate'/></td></tr>
</table>
</form>