Delete some UL if empty
<p>right now my output is something like this
<a href="https://i.stack.imgur.com/Cj6ik.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Cj6ik.png" alt="enter image description here"></a></p>

<p>I want to delete the list that are empty</p>

<p>just tried this code empty or isset inside the listitems</p>

<pre><code>&lt;?php if(isset($page)): //but i got different output   ?&gt;
</code></pre>

<p>even something like </p>

<pre><code>&lt;?php if(empty($page): //but i got an error    ?&gt;
</code></pre>

<p>heres my running code without if statement</p>

<pre><code>&lt;?php 
$letter='A';
for($i= 1; $i &lt;=26 ;$i++,$letter++):?&gt;
&lt;?php 

    $pages = $db-&gt;prepare("
    SELECT * FROM pages WHERE LEFT(`title`, 1) = '".$letter."'

    ");
    //$check =$db-&gt;query("SELECT * FROM watch WHERE animelist_id=".$page['id']." and acc_id=".$_SESSION["user_id"]."");
    $pages-&gt;bindParam(1,$letter, PDO::PARAM_STR);
    $pages-&gt;execute();
?&gt;

&lt;div class = "listitems"&gt;

    &lt;?php echo '&lt;h5&gt;'.$letter.'&lt;/h5&gt;';?&gt;
            &lt;?php foreach($pages as $page): ?&gt;

                        &lt;ul&gt;
                            &lt;li&gt;
                            &lt;a href="&lt;?php echo BASE_URL;?&gt;/page.php?page=&lt;?php echo e($page['slug']);?&gt;"&gt;&lt;?php echo e($page['label']);?&gt;&lt;/a&gt;

                            &lt;/li&gt;
                        &lt;/ul&gt;



            &lt;?php endforeach; ?&gt;

&lt;/div&gt;
&lt;?php endfor; ?&gt;
</code></pre>