I am trying to get specific information from database and specific for each user. I want to loop through an object and get a specific information (string) from 2 different field in database. Each 2 field combine will create a link to download a file.(those file will be located inside project folder)
I need to loop through the database get the field and display it, of course database will containe many link-file.
Here the database structure:
- file_id (int)
- file_name (name)
- file_extension (pdf)
- user_id (int)
Here is class file to get full info from user:
public $file = array();
public $pdo = '';
public function __construct($id)
{
$this->pdo = new PDO('mysql:host=127.0.0.1;dbname=****', '***', '***', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$sql = 'SELECT `name`, `file_name`, `file_extention` FROM `users`'
.'JOIN `file`'
.'ON users.`user_id` = file.`user_id`'
.'WHERE users.`user_id` = :id';
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array(':id' => $id));
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$this->file[] = $row;
}
}
Here is view class display :
public function displayFile($link)
{
$output = '';
$output .= '<p><a href="#"><i class="fa fa-folder"></i>  '. $link.'</a></p><br />';
return $output;
}
I need to get a link like :
$link = [file_name].'.'.[file_extension];
Final result for public should be :
- link to file 01
- link to file 02
- link to file 03
- etc....