Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Disk Access = slow</h3> <p>You have a couple of options. One is to check that the file exists each and every time you need to display it. Unfortunately, this is less than ideal because disk reads can be a performance bottleneck. It's not a tenable solution if you're serving up hundreds of page loads a minute. In high-performance environments you want to avoid as many file stats as possible:</p> <pre><code>$img_dir = '/path/to/artist/images'; $expected_file = $img_dir . '/' . $artist_name . '.jpg'; $img = file_exists($expected_file) ? $artist_name : 'default'; </code></pre> <h3>Hard-code the names into your code</h3> <p>Another, if you have a small number of artists whose images you need to display is to hard-code in the names for the images you have:</p> <pre><code>$authors = array('Bill Shakespeare', 'Douglas Adams', 'Ralph Ellison'); $img = in_array($artist_name, $authors) ? $artist_name : 'default'; </code></pre> <p>Of course, this isn't particularly helpful because then you'll need to edit your code each time your catalog of artist images changes.</p> <h3>The best idea ...</h3> <p>The preferred option in this instance would be this: </p> <blockquote> <p>Since you're already hitting the database to get the artist records, store the relevant image filename in a database column of the artists table. That way you can avoid the superfluous disk access.</p> </blockquote> <p>This method allows you to retrieve the filename from the database with your original query. If the field is empty you'll know to display the default image instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload