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
https://forums.phpfreaks.com/topic/277250-convert-hardcoded-array-using-pdo/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.