Hello guys, quick question for ya...

Here is the code i am looking at

$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;

  // done!
  return $password;

$query=("SELECT * FROM graduates") or die(mysql_error());
$result=mysql_query($query) or die(mysql_error());
$sql="update graduates set password=SHA1('$password') where firstname='$userid'";

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.


Dani C

7 Years
Discussion Span
Last Post by dani190
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.