how to generate random password
<p>i just want to have random password from all the query results i did of the students. on my situation, i tried to generate but it returns only 1 generated password to all queried students(about 45 students). how should i make a random one. plss help..
heres my code</p>

<pre><code>   &lt;?php
   if(isset($_POST['generate'])){
   $charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&amp;*()_+';
    $generated_pass = substr(str_shuffle($charset), 0, 12);
    $generate = $_POST['generate'];
    }
    ?&gt;
    &lt;form method="post" action='enroll_student.php' name ='register'&gt;

     &lt;?php
     $yr = date("Y");
     if ($result = $mysqli-&gt;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-&gt;num_rows &gt; 0)
       {
                echo "&lt;table width= '1000'&gt;";
                echo "&lt;tr&gt;&lt;th&gt;StudentID&lt;/th&gt;&lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Date of Birth&lt;/th&gt;&lt;th&gt;Address&lt;/th&gt;&lt;th&gt;Department&lt;/th&gt;&lt;th&gt;School Year&lt;/th&gt;&lt;th&gt;Password&lt;/th&gt;&lt;/tr&gt;";

         while ($row = $result-&gt;fetch_object())
          {
           echo "&lt;tr&gt;";

        echo "&lt;td align='center'&gt;" . $row-&gt;studId . "&lt;/td&gt;";  
        echo "&lt;td align='center'&gt;" . $row-&gt;fname . " ". $row-&gt;mname ." ". $row-&gt;lname ." &lt;/td&gt;";
    echo "&lt;td align='center'&gt;".$row-&gt;dob."&lt;/td&gt;";
    echo "&lt;td align='center'&gt;" . $row-&gt;address. "&lt;/td&gt;";
    echo "&lt;td align='center'&gt;".$row-&gt;departmentName."&lt;/td&gt;";
    echo "&lt;td align='center'&gt;".$row-&gt;sy."&lt;/td&gt;";

   if(isset($generated_pass)) {
        //how could i make this one generate random password for every students..?
    for($i=0; $i &lt;= $row-&gt;studId; $i++){              
    echo "&lt;td&gt;$generated_pass&lt;/td&gt;";
        }
        }
  echo "&lt;/tr&gt;";
        }
echo "&lt;/table&gt;";
                }
              else
                {
              echo "No Results.";
                }
                }
              else
                {
              echo "Error: " . $mysqli-&gt;error;
                 }
            $mysqli-&gt;close();
            echo '&lt;br&gt;';
    include 'count.php'; //this one will give the total no. of results, just ignore.
            ?&gt;

               &lt;br /&gt;        

          &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;input type='submit' name='generate' value='Generate'/&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;/table&gt;
          &lt;/form&gt;
</code></pre>
