Hello guys, quick question for ya...

Here is the code i am looking at

<?php
$conn=mysql_connect("internal-db.s*****.gridserver.com","db*****","*******") or die(mysql_error());
mysql_select_db("db*****_gradsurvey") or die(mysql_error());


function generatePassword ($length = 5)
{

  // start with a blank password
  $password = "";

  // define possible characters
  $possible = "0123456789"; 
    
  // set up a counter
  $i = 0; 
    
  // add random characters to $password until $length is reached
  while ($i < $length) { 

    // pick a random character from the possible ones
    $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
        
    // we don't want this character if it's already in the password
    if (!strstr($password, $char)) { 
      $password .= $char;
      $i++;
    }

  }
  
  // done!
  return $password;

}
$query=("SELECT * FROM graduates") or die(mysql_error());
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result)){
$userid=$row['firstname'];
$userid2=$row['lastname'];
$student_ip=$row['student_ip'];
$homeroom=$row['homeroom'];
$password=generatePassword(5);
$sql="update graduates set password=SHA1('$password') where firstname='$userid'";
mysql_query($sql);

echo "<p>",$userid."  ",$userid2," , ",$student_ip," , ",$homeroom," , ".$password,"</p>\n\n"; //remove this if you dont want to see the user id and password on the screen
}
?>

so basically this script looks at my mysql database which has firstnames, lastnames, student numbers, and homerooms of graduating students.

What i want to do is when the script is run, it outputs the name, student number and home rooms, and password just generated of all the students in the database.

What i want is for this data to be sorted by homeroom, that way we can distribute lists...

Sorry i am a little rough around the edges with php, as i wrote this script last year...

So any help would be greatly appreciated.


Thanks,

Dani C

This article has been dead for over six months. Start a new discussion instead.