Jump to content

convert hardcoded array using PDO


kino

Recommended Posts

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 } }?>
 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.