Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

HTML & CSS How to rerun php code depending on button clicked

mdavid

Coder
Hi, I'm building a gallery site for paintings - the paintings are divided into groups eg. Oil on canvas, Water Color etc.
This is the PHP loop I have for displaying Oil on canvas:
PHP:
if ($entry['medium'] == "Oil on canvas") {
             $count++;
            
             $nxtNum = $count + 1;
             echo "<a id='pic{$count}'><span style='visibility: hidden;'>hi</span></a> ";
             echo "<div class='grid-container'> ";
             // start prv-nxt
             echo "<div class='grid-item prv-nxt'>";
             if ( $count > 1) {
                 $prvNum = $count - 1;
                  echo "<a href='#pic{$prvNum}'><i class='fa-style fa-solid fa-caret-up' style='font-size: 2.5rem;'></i></a><br/>";
                } 
             echo "<a href='#pic{$nxtNum}'><i class='fa-style fa-solid fa-caret-down' style='font-size: 2.5rem;'></i></a></div>";
             // end prv-nxt
             // start imgMain
            echo "<div class='grid-item imgMain'>";
            echo "<img class='example lazyload' src='{$imagesDirectory}{$image}' data-src='{$imagesDirectory}{$image}' data-sizes='auto' data-magnify-src='{$imagesDirectory}{$image}'></div> ";
             // end imgMain
            // start lableTxt
            echo "<div class='flex-container'>";
            echo "<div class='flex-items' style='{$captPos}'>{$title}</div>";
            echo "<div class='flex-items' style='{$captPos}'>{$medium}</div>";
            echo "<div class='flex-items' style='{$captPos}'>{$year} {$size}</div>";
            echo "</div></div>";
      }
}
What is the best way to enable the user to rerun the above code (using button onClick event - or similar) to view other painting groups eg.
if ($entry['medium'] == "Water color") {
Using the same page?
Any code snippets, pointers much appreciated
 
I don't think you need to define thing with if ($entry['medium'] == "Oil on canvas")
It may be in the items you don't define in your clip like:
$imagesDirectory,
$image,
and may be $captPos
 
Hi OldMan,
Thanks for this. Didn't quite understand how this would change what's displayed.
I had a brainwave - well I thought it was quite clever - if I load everything (I'm using lazy-loading)
and then just toggle between display: none/block depending on which group to display?
Is that a reasonable solution? - not sure how to implement it though.
 

Latest posts

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom