Created
July 8, 2015 06:20
-
-
Save shadda/8329cf3665e61e0d0113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $db = new PDO("mysql:dbname=mydb;host=localhost", $user, $password); | |
| $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
| function get_row($parent_id) | |
| { | |
| global $db; //I would normally never do this, but its simpler than explaining the concept of a singleton | |
| $parent_id = (int) $parent_id; //Cast to int | |
| $q = $db->prepare(" | |
| SELECT | |
| posts.post_topic, posts.post_content, posts.post_id, posts.post_date, posts.file_uploaded, | |
| posts.post_by, posts.post_parent, users.user_id, users.user_name, users.user_pic | |
| FROM | |
| posts | |
| LEFT JOIN users ON posts.post_by = users.user_id | |
| WHERE | |
| posts.topic_id = :parent_id | |
| "); | |
| $q->execute( | |
| array( | |
| ':parent_id' => $parent_id | |
| ) | |
| ); | |
| while($row = $q->fetch(PDO::FETCH_OBJ)) | |
| { | |
| if($row->parent_id != NULL) | |
| { | |
| get_row($row->parent_id); | |
| } | |
| //Do other shit with $row here | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment