title: PHP dynamically defined variable (to use in a while loop with two conditions)
body: <p>I thought I would simplify my question and start with trying to solve one problem at a time instead of two. The -1 rating tells me I was not clear enough, so I will try again. My original post is quoted below.</p>
  
  <p>With the following code I can display data from my table that meets the condition that the category is Scenics:</p>
  
  <pre><code>&lt;?php
  $category = $_GET['category'] ?? 'Scenics';
  
  $sql = "SELECT * FROM photo_library ";
  $sql .= "WHERE category='" . $category . "' ORDER BY id ASC";
  $image_set = mysqli_query($db, $sql);
  $image_set_desc = mysqli_query($db, $sql);
  ?&gt;
  </code></pre>
  
  <p>What I want to do is have dynamically set. Instead of <code>$category = $_GET['category'] ?? 'Scenics';</code>, is there a way not set the way it is above? I would like it be set by whatever it finds in the 'category' column of my SQL table so that later I can say while category is Scenics and sub_category is Coastal, display just that info (so I will need to do something similar for sub_category).</p>
  
  <p><strong>EDIT:</strong> The term I was looking for was <strong>array</strong>. I want $sub_category to be an <strong>array</strong> based on what is found in the sub_category column of my SQL table.</p>
  
  <p>I am also aware of the risk of using $_GET, but this would be on a protected site where you only get access if you are a member, and you are only a member if you apply and are manually approved for access. And there is no user input in the protected part of the site. It is strictly a resource site for downloading graphics and images.</p>
  
  <blockquote>
    <p>I am playing around with having an image gallery be generated using
    PHP and My SQL instead of coding everything in HTML on the page. I've
    created a test table that has multiple columns, and a working page
    where all the info gets pulled in and displayed.</p>
    
    <p>The two main values that will be used to separate image entires from
    each other are 'category' and 'sub_category'. The page that is working
    only uses the category and works great.</p>
  
  <pre><code>&lt;?php
   $category = $_GET['category'] ?? 'Agroforestry';
  
   $sql = "SELECT * FROM photo_library ";
   $sql .= "WHERE category='" . $category . "' ORDER BY id ASC";
   $image_set = mysqli_query($db, $sql);
   $image_set_desc = mysqli_query($db, $sql);
  ?&gt;
  </code></pre>
    
    <p>$image_set pulls in the info for the actual image, and $image_set_desc
    does the work for the links and file size. This is the pulling in of
    the thumbnail:</p>
  
  <pre><code>&lt;?php while($subject = mysqli_fetch_assoc($image_set)) { ?&gt;
  &lt;li&gt;&lt;a href="&lt;?php echo h($subject['jpg_location']); ?&gt;" title="&lt;?php echo h($subject['title']); ?&gt;" data-title="&lt;?php echo
  </code></pre>
    
    <p>h($subject['id']); ?>">" src="#" alt="" aria-describedby=""></li>
        </p>
  
  <pre><code>&lt;?php while($subject_desc = mysqli_fetch_assoc($image_set_desc)) { ?&gt;    
  &lt;p id="&lt;?php echo h($subject_desc['id']); ?&gt;"&gt;&lt;b&gt;Filename:&lt;/b&gt; &lt;?php echo h($subject_desc['filename']); ?&gt;&lt;br&gt;
  &lt;a class="btn btn-default btn-xs mrgn-tp-sm" role="button" href="&lt;?php echo h($subject_desc['tif_location']); ?&gt;"&gt;TIFF &lt;span
  </code></pre>
    
    <p>class="wb-inv">image download () ">JPG image
    download ()</p>
        </p>
    
    <p>The problem is on the next page I am testing this on, there are a lot
    more pictures and they are broken up into multiple sub-categories. I
    only want to display pictures with certain sub-categories under their
    respective headings.</p>
    
    <p>I am very new to PHP, and do not know how to set something like
    $sub_category to whatever it finds in that column. I cannot use</p>
  
  <pre><code>$sub_category = $_GET['sub_category'] ?? 'Coastal';
  </code></pre>
    
    <p>because the sub-category needs to be pulled from the SQL table. I
    don't know what I am doing so while </p>
  
  <pre><code>$sub_category = isset($_GET['sub_category']);
  </code></pre>
    
    <p>doesn't break anything, it also doesn't seem to work. If that somehow
    works, then</p>
  
  <pre><code>&lt;?php while(($subject = mysqli_fetch_assoc($image_set)) &amp;&amp; ($sub_category == 'Coastal')){ ?&gt;
  </code></pre>
    
    <p>is not because nothing is generated on the page. I'm not sure if my
    problem is with defining $sub_category, the while loop, or both.</p>
  </blockquote>