Skip to content

Instantly share code, notes, and snippets.

@nootanghimire
Last active December 22, 2015 20:39
Show Gist options
  • Save nootanghimire/6527881 to your computer and use it in GitHub Desktop.
Save nootanghimire/6527881 to your computer and use it in GitHub Desktop.
Get upto second child!
<?php
$q = "SELECT * FROM table WEHRE parent=0" ;
$res = mysql_query($q);
while ($row = mysql_fetch_array($res)){
$q1 = "SELECT * FROM table WHERE parent = ". $row['id'];
$res1 = mysql_query($q1);
while($row1 = mysql_fetch_array($res1){
$q2 = "SELECT * FROM table WHERE parent = ". $row1['id'];
$res2 = mysql_query($q2);
while($row2 = mysql_fetch_array($res2)){
//echo Parent: $row
// First Child: $row1
// Second Child: $row2
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment