How do I set a specific CSS stylesheet to load If a specific database id is set? [closed]

I am working on a project in Codeigniter 3.1.9 on PHP 8.2.12.

My question is I have a lot of dynamic data that gets brought into a static view to create multiple pages. The issue I have is that without creating my own PDF Library, or having every page identical, I would need to bring in different print style sheets for each page instance. I could bring in all the different stylesheets at once, so they all load every time a page loads, but that feels a bit clunky and unnecessary.

So, the solution I was hoping for is to have different stylesheets load in dynamically depending on which record is pulled in, with PHP. I already am doing this this with an admin check on the admin elements and styles which works beautifully. However, those instances are loading in stylesheets and elements that are fairly static from fixed views.

Here is the Recipe Controller:

<?php
 
 class Recipe extends BaseController{

  function __construct(){
   parent::__construct();
   
   // Loading in Pagination Library
   $this->load->library('pagination'); 
   
   // Loading in Recipe_model
   $this->load->model('recipe_model');
   
   $uri = $this->uri->uri_string();
   $this->session->set_flashdata('uri', $uri);
  }
    
  function index(){
   $recipe_linkname = $this->uri->rsegment(3);
   if(!$recipe_linkname){
    $recipe_linkname = $this->recipe_model->first_linkname();
   }
   $recipe = $this->recipe_model->read_record($recipe_linkname);
   if(count($recipe) == 0){
    show_404('');
    die();
   }
   $data = array(
    'title' => "Shirley's Recipes:".$recipe['name'], 
    'columns' => array('toc', 'recipe'), 
    'recipe' => $recipe, 
    'updated' => $this->format_date($recipe['updated'])
    );
   $this->load->view('templates/main', $data);
  }
    
  function flipbook(){  
   
   // Requires the user to be "logged in"   
   $this->require_login();  
   
   // Recipe Flipbook Pagination Configuration
   $config['base_url'] = site_url('recipe/flipbook');
   $config['total_rows'] = $this->recipe_model->num_rows();
   $config['uri_segment'] = '3';
   $config['per_page'] = 1;
   $config['num_links'] = 9; // You will see 10 numerical link buttons in paginnation.
   $config['display_pages'] = TRUE;
   $config['full_tag_open'] = '<div id="pagination" class="grid-item3">';
   $config['full_tag_close'] = '</div>'; 

   // Initialize the Pagination Library
   $this->pagination->initialize($config);  
   
   $recipe = $this->recipe_model->read_records($config['per_page'], $this->uri->segment(3))->row_array();
   $data = array(
    'title' => "Shirley's Recipes:".$recipe['name'], 
    'columns' => array('toc', 'admin/page/recipe_flipbook'), 
    'recipe' => $recipe,
    'updated' => $this->format_date($recipe['updated'])
   );   
   $this->load->view('templates/main', $data);
  }
  
  function search(){
   if($this->input->method() === 'post'){           
    $search = $this->input->post('query');  //modify here:        
    $results = $this->recipe_model->search($search);
    $page = $this->uri->segment(3);
    $perPage = 19;    
    $results = $this->recipe_model->search($search, $page, $perPage);
    $data = array(
     'title' => "Shirley's Recipes:Search Results", 
     'columns' => array('toc', 'public/page/search_results'), 
     'recipes' => $results,  // $results is being renamed $recipes. I don't really know why though yet...
     'search' => $search
    );
    $this->load->view('templates/main', $data);
   }
   else{            
    redirect('recipe');
   }
  } 
    
  function add(){
      
   // Requires the user to be "logged in"     
   $this->require_login();

   if($this->input->post('submit')){
    $data = array(
     'id' => $this->input->post('id'),  
     'name' => $this->input->post('name'), 
     'buttontext' => $this->input->post('buttontext'), 
     'linkname' => $this->input->post('linkname'), 
     'time' => $this->input->post('time'),      
     'category' => $this->input->post('category'), 
     'subcategory' => $this->input->post('subcategory'),
     'img' => $this->input->post('img'),
     'keywords' => $this->input->post('keywords'),   
     'ingredients' => $this->input->post('ingredients'), 
     'equipment' => $this->input->post('equipment'), 
     'prepreparation' => $this->input->post('prepreparation'), 
     'directions' => $this->input->post('directions')
    );
    $recipeid = $this->recipe_model->create_record($data);
    redirect('recipe/'.$this->input->post('linkname'));
   }
   else{ // If the IF statement returns false, then  the ELSE statement tells php to do something else.
    $data = array(
     'title' => "Shirley's Recipes:Add New Recipe", 
     'columns' => array('toc', 'admin/edit-page/recipe_edit'), 
     'recipe' => array(
      'id' => '',
      'name' => '', 
      'buttontext' => '', 
      'linkname' => '', 
      'time' => '', 
      'category' => '', 
      'subcategory' => '',    
      'img' => '',
      'keywords' => '',   
      'ingredients' => '', 
      'equipment' => '', 
      'prepreparation' => '', 
      'directions' => ''
     )
    );
    $this->load->view('templates/main', $data);
   }
  }
  
  function edit(){
      
   // Requires the user to be "logged in"     
   $this->require_login();
   
   $id = $this->uri->segment(3);
   if($this->input->post('submit')){
    $data = array(
     'name' => $this->input->post('name'), 
     'buttontext' => $this->input->post('buttontext'), 
     'linkname' => $this->input->post('linkname'), 
     'time' => $this->input->post('time'),    
     'category' => $this->input->post('category'), 
     'subcategory' => $this->input->post('subcategory'),
     'img' => $this->input->post('img'),     
     'keywords' => $this->input->post('keywords'), 
     'ingredients' => $this->input->post('ingredients'), 
     'equipment' => $this->input->post('equipment'), 
     'prepreparation' => $this->input->post('prepreparation'), 
     'directions' => $this->input->post('directions')
    );
    $this->recipe_model->update_record($id, $data);
    redirect('recipe/'.$this->input->post('linkname'));
   }
   else{ // If the IF statement returns false, then  the ELSE statement tells php to do something else.
    $recipe = $this->recipe_model->read_record($id);
    $data = array(
     'title' => "Shirley's Recipes:Edit Recipe : ".$recipe['name'], 
     'columns' => array('toc', 'admin/edit-page/recipe_edit'), 
     'id' => $id, 
     'recipe' => $recipe
    );
    $this->load->view('templates/main', $data);
   }
  }
    
  function delete(){
      
   // Requires the user to be "logged in"     
   $this->require_login();
   
   $this->recipe_model->delete_record($this->uri->segment(3));
   redirect('/');
  } 
 }

 // End of recipe.php

?> 

Here is the Recipe_model.php

<?php

 class Recipe_model extends CI_Model{

  function create_record($data){
   if(isset($data['buttontext']) and $data['buttontext'] == ''){
    $data['buttontext'] = NULL;
   }
   $this->db->insert('recipe', $data);
   return $this->db->insert_id();
  }
  
  function read_records($limit, $offset){
   $this->db->order_by('name', 'asc');
   if(isset($limit) && isset($offset)){
    $this->db->limit($limit, $offset);
   }
   $q = $this->db->get('recipe');
   return $q;
  }
  
  function read_record($key){
   if(is_numeric($key)){
    $this->db->where('id', $key);
   }
   else{
    $this->db->where('linkname', $key);
   }
   $q = $this->db->get('recipe');
   return $q->row_array();
  }
  
  function first_linkname(){
   $this->db->select('linkname, name');
   $this->db->order_by('name', 'asc');
   $this->db->limit(1);
   $q = $this->db->get('recipe');    
   return $q->row()->linkname;
  }
        
  function read_names(){
   $this->db->select('linkname, name');
   $this->db->order_by('name', 'asc');
   $q = $this->db->get('recipe');
   return $q->result();
  }
  
  function read_names_categories(){
   $this->db->select('buttontext, linkname, name, category, subcategory, img, time');
   $this->db->order_by('name', 'asc');
   $q = $this->db->get('recipe');
   return $q->result();  
  }
    
  function search($search, $currentPage = 1, $perPage = 19){ 
  $offset = ($currentPage = 1) * $perPage;
  $terms = explode(' ', $search); 
  $match = " ";       
  foreach($terms as $term){      
   $match .= $term;
  }       
  $querystr = "SELECT id, name, category, subcategory, keywords, MATCH(name, category,  subcategory, keywords) AGAINST('".$match."') as score FROM recipe WHERE  MATCH(name, category, subcategory, keywords) AGAINST('".$match."') ORDER BY name LIMIT 60 OFFSET 0;";
  $q = $this->db->query($querystr);   
  return $q->result();
 }

  function update_record($id, $data){
   if(isset($data['buttontext']) and $data['buttontext'] == ''){
    $data['buttontext'] = NULL;
   }
   $this->db->where('id', $id);
   $this->db->update('recipe', $data);
  }
  
  function delete_record($id){
   $this->db->where('id', $id);
   $this->db->delete('recipe');
  }
  
  function num_rows(){
   return $this->db->get('recipe')->num_rows();
  }
 }

 // End of Recipe_model.php

?>

Here is the static recipe.php View

<link rel="stylesheet" type="text/css" href="/assets/css/public/page/recipe.css" media="screen" />
<link rel="stylesheet" type="text/css" href="/assets/css/public/page/print/printrecipe.css" media="print" />

<div id="sitecontent" class="grid-item2 grid-container">
<!-- Loads ADMIN items or CSS Stylesheets needed when logged in as ADMIN. -->
 <?php
  if($admin){
   echo '<link rel="stylesheet" type="text/css" href="/assets/css/admin/core/admin.css" />';
   echo '<link rel="stylesheet" type="text/css" href="/assets/css/admin/core/wmd.css" />';
   echo '<link rel="stylesheet" type="text/css" href="/assets/css/admin/page/recipeadmin.css" />';
   echo '<script type="text/javascript" src="/assets/js/wmd.min.js"></script><br>';
   echo '<script type="text/javascript" src="/assets/js/showdown.js"></script><br>';
   echo '<script type="text/javascript" src="/assets/js/confirmdelete.js"></script>';
   $this->load->view('admin/nav/notesnav');
  }
 ?>
 <div id="contents" class="<?php if($admin){echo 'grid-item2';} ?> grid-item1 grid-container scrollbar">
  <div id="spiral" class="grid-item1">
   <img class="spiral" src="/assets/img/lines/spiral1trans.png"/> 
  </div>
  <div id="recipe" class="grid-item2 grid-container">
  <div id="title" class="grid-item1">
   <?=$recipe['name']; ?>
   <br>
   <?=$recipe['time']; ?>
  </div>
  <div id="image" class="grid-item2">
   <?=$recipe['img']; ?>
  </div>
  <div id="ingredients" class="grid-item3">
   <h2>Ingredients:</h2>
   <?php 
    if(isset($recipe['ingredients']) && $recipe['ingredients'] != ''){
     echo $this->mkdn->translate($recipe['ingredients']);
    }
    else{
     echo '<br><br><br><br><br><br><br><br><br><br><br>';
    }
   ?>
  </div>
  <div id="equipment" class="grid-item4">
   <h2>Equipment:</h2>
    <?php 
     if(isset($recipe['equipment']) && $recipe['equipment'] != ''){
      echo $this->mkdn->translate($recipe['equipment']);
     }
     else{
      echo '<br><br><br><br><br><br><br><br><br><br><br>';
     }
    ?>
   </div>
   <div id="prepreparation" class="grid-item5">
    <h2>Pre-Preparation:</h2>
    <?php 
     if(isset($recipe['prepreparation']) && $recipe['prepreparation'] != ''){
      echo $this->mkdn->translate($recipe['prepreparation']);
     }
     else{
      echo '<br><br><br><br><br><br><br><br><br><br><br>';
     }
    ?>
   </div>
   <div id="directions" class="grid-item6">
    <h2>Directions:</h2>
    <?php 
     if(isset($recipe['directions']) && $recipe['directions'] != ''){
      echo $this->mkdn->translate($recipe['directions']);
     }
     else{
      echo '<br><br><br><br><br><br><br><br><br><br><br>';
     }
    ?>
   </div>   
  </div>
 </div> 
 <?php
  if(isset($updated)){
   echo '<div id="updated" class="grid-item2">Updated '.$updated.'</div>';
  }
   if($admin){
    echo '<div id="optionbuttons" class="grid-item noprint">';
    echo anchor('recipe/edit/'.$recipe['id'], img(array('src'=>'assets/img/icons/edit.png', 'alt'=>'Edit', 'title'=>'Edit')));
    echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
    echo '<a href="javascript:confirmdelete('Delete recipe?',''.base_url().'recipe/delete/'.$recipe['id'].'')">'.img(array('src'=>'assets/img/icons/delete.png', 'alt'=>'Delete', 'title'=>'Delete')).'</a>';
    echo '</div>';
   }
  ?>
</div> 

<?php
  if($admin){
   echo '';   
  }
?>

Could I accomplish this with an IF statement and how would I set it up?

I tried setting the stylesheets to load individually, however with the if statement I wrote they both loaded anyway.

My if statement looked something like this:

<?php
 if($recipe['linkname'] = 'gallonsizesweettea'){
  echo '<link rel="stylesheet" type="text/css" href="/assets/css/public/page/print/recipes/printgallonsizesweettea.css" media="print" />';
 }
 if($recipe['linkname'] = 'applecobbler'){
  echo '<link rel="stylesheet" type="text/css" href="/assets/css/public/page/print/recipes/printapplecobbler.css" media="print" />';
 }
?>

What am I missing here? Thanks in advance for any help anyone could offer!