How to Use looping on PHP and MySQL? -


hello have tables :

employee

employeeid  employeename  1234        minjun    1235        nichkhun      1236        taecyeon      1237        wooyoung      1238        junho        1239        chansung 

i used source code :

    <?php  mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("employee") or die(mysql_error());  $employees = mysql_query("select * employee order employeeid")  or die(mysql_error());     $letters = 'abcdefghijklmnopqrstuvwxyz';   $array = array();   while($row = mysql_fetch_assoc($employees)){  $array[] = $row; }   $i = 0;   // assign letter each employee in correct order  foreach($array $key => $row){  $array[$key]["letter"] = substr($letters, $i, 1);  $i++;  if($i > 25){  $i = 0;  }  }   // shuffle array  shuffle($array);   // print each entry correctly assigned letter , name.  foreach($array $row) {  echo "<div>" . $row["letter"] . " = " . $row['employeename'] . " </div>";  }   ?> 

to display random data :

e = junho b = nichkhun c = taecyeon f = chansung d = wooyoung = minjun 

or :

b = nichkhun d = wooyoung f = chansung e = junho = minjun c = taecyeon 

the problem want display 10 type of varian random :

e = junho b = nichkhun c = taecyeon f = chansung d = wooyoung = minjun   f = chansung d = wooyoung c = taecyeon e = junho b = nichkhun = minjun  = minjun d = wooyoung e = junho b = nichkhun f = chansung c = taecyeon  d = wooyoung b = nichkhun c = taecyeon = minjun e = junho f = chansung  c = taecyeon d = wooyoung f = chansung = minjun e = junho b = nichkhun  = minjun f = chansung c = taecyeon e = junho d = wooyoung b = nichkhun  c = taecyeon d = wooyoung f = chansung b = nichkhun = minjun e = junho  e = junho c = taecyeon b = nichkhun f = chansung d = wooyoung = minjun  e = junho b = nichkhun = minjun d = wooyoung f = chansung c = taecyeon  d = wooyoung = minjun c = taecyeon b = nichkhun f = chansung e = junho 

so add codes :

  <?php  mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("employee") or die(mysql_error());  $employees = mysql_query("select * employee order employeeid")  or die(mysql_error());     $letters = 'abcdefghijklmnopqrstuvwxyz';   $array = array();   while($row = mysql_fetch_assoc($employees)){  $array[] = $row; }   $i = 0;   // assign letter each employee in correct order  foreach($array $key => $row){  $array[$key]["letter"] = substr($letters, $i, 1);  $i++;  if($i > 25){  $i = 0;  }  }   // shuffle array  shuffle($array);   // print each entry correctly assigned letter , name.  ($i=1; $i<=10; $i++){  foreach($array $row) {  echo "<div>" . $row["letter"] . " = " . $row['employeename'] . " </div>";  echo "";  } }  ?> 

but result (looping 1 result 10 times):

c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho  c = taecyeon d = wooyoung b = nichkhun = minjun f = chansung e = junho 

may know problem? thank you

update 'for loop' below , try

 //shuffle($array); //comment line      ($i=1; $i<=10; $i++){     shuffle($array);     foreach($array $row) {      echo "<div>" . $row["letter"] . " = " . $row['employeename'] . " </div>";      echo "";      }     } 

Comments