kino Posted April 24, 2013 Share Posted April 24, 2013 Hi I have the following class <?php include_once("model/Event.php"); class Model { public function getEventList() { return array( "1" => new Event("1","title1","abstract","content","userID","dateAdded"), "2" => new Event("3","title1","abstract","content","userID","dateAdded"), "3" => new Event("3","title1","abstract","content","userID","dateAdded") ); } public function getEvent($eventID) { $allEvents = $this->getEventList(); return $allEvents[$eventID]; } } ?> I am struggling to find out how to use PDO to use the same functionality i wish to add ten latest events by creating a new event object with details from the database the code below is what I am hoping to achieve but with pdo instead thanks in advance for any help. I //Queries the database and shows the latest 10 events of clubs that the user is a member of. $event_query = "SELECT * FROM event INNER JOIN taking ON event.club_id=taking.club_id where user_ID = $user ORDER BY date_added DESC"; $club_query = "SELECT id FROM club_id"; //Stores the row of the query in rows. $rows = perform_query($event_query); //Loops through events and displays details of 10 events by the most recently added. If no events are found a message is displayed. for($i=0; $i<10; $i++){ if ($rows ->rowCount()>0) { foreach ($rows as $row) { ?> <article class="recommendedevent"> <figure class="eventimage"> <figcaption class=""><?= $row["title"] ?></figcaption> <img class="" href=""src="upload/<?= $row["event_pic"] ?>" alt="<?= $row["title"] ?>"width="100" height="100"> <figcaption class="">Added on:<?= $row["date_added"] ?></figcaption> </figure> <p class="abstract"><?= $row["abstract"] ?></p> </article> <?php } ?> <?php } else { ?> <p>No events Available.</p> <?php } }?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.