mysql - PHP Looping and foreach -


i explain problem single example.

  1. i have set of email ids (fetch db , dynamic). let there 100 email ids

  2. i need group them count of 10. in other words, 100 email ids divided 10 => there 10 loops.

  3. the output should like

group1: ---first ten email ids---

group2: ---next ten email ids--- . . . . ..

group3: ---last ten email ids---

here php code(i have revised/corrected code)

    <?php     $con=mysql_connect("localhost","root","admin");     mysql_select_db("test1",$con);     $sel=mysql_query("select distinct emailaddress userlist");     while($row=mysql_fetch_array($sel))     {     $mail[]=$row['emailaddress'];     }       $chunk = array_chunk($mail, 10);     $get_chunk_count = count($chunk);       for($i=0;$i<$get_chunk_count;$i++){     echo "group :".$i;     echo "<br>";     echo "========";     echo "<br>";     $count_inside_count = count($chunk[$i]);      for($j=0;$j<=$count_inside_count;$j++){     echo "<pre>";     echo $chunk[$i][$j];     echo "</pre>";     }     }     ?> 

edited: above code works fine, , have edited. :)

you make use of php's array_chunk() function break array smaller chunks.

not tested should pretty close think.

$chunk = array_chunk($mail, 10); $i = 0; {     echo $chunk[$i] . '<br />';     $i++;     if($i == 10)         sleep(10); } while ($i < count($chunk));  

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -