Trying to show divs and elements when a session doesn't exist. But when I save an item to a cart/wish-list a session starts and goes back to a page that is now supposed to show the item info and hide <td id="cartHideBtn">...</td>.

//shows when no session exists, but also needs to show again if user removes item from cart/wish-list, or show when another part is added 
//in a different category
<td id="cartHideBtn" class="add-component">
    <a href="content.php?PartType=UpperReceiver" class="add-btn"><i class="fas fa-plus"></i>ADD</a>
</td>

If session exists and a product is added then display this.

<?php
    if (isset($_SESSION['buildList'])) {
        foreach ($_SESSION['buildList'] as $product) :
            if ($product['PartType'] == 'UPPER RECEIVER') {
?>

<tr>
    <td>
        <a href="pageContent.php?id=<?php echo $product['id'];?>"><img class="p-img" src="<?php echo $product['Image_thumb'];?>"/></a>
    </td>
    <td>
        <h6>MANUFACTURER</h6>
            <p>
                <?php
                    echo $product["Manufacturer"];
                ?>
            </p>
    </td>
    <td>
        <p><?php echo $product["Price"];?></p>
    </td>
</tr>

//this is button to remove item.
<td class="td-remove">
    <form method="get" action="./controllers/WishBuild.php" class="fm-remove">
        <input type="hidden" name="type" value="remove">
        <input type="hidden" name="id" value="<?php echo $product['id'];?>">
        <button type="submit" name="removed" class="rem-btn"><i class="fas fa-minus"></i>REMOVE</button>
     </form>
</td>                  

<?php
            }
        endforeach;
    } 
?>

I have several categories, titled Part1, Part2, Part3...etc. So the above code is for one category. Basically, part1 takes you to part1 products and so on, if product in part1 is added then display it in part1 then user goes onto adding part2...etc. So far the above code works I can add the products and they show where they need to be but the "add" links still show and want them to be hidden. Trying to figure out best way to do this and how. Thanks for any input.

Ok here you need to first have some sort of differentiating when (a) the session doesn't exist then also (b) when the user has click remove then finally (c) another part is added to the category. That will be done by you but this will help you in that:

<?php echo $_SESSION['your_session'] == "" ? 'show' : 'hidden';?>

then for checking if the user has removed item you will need to have a global variable or make use of toggle through a function which will trigger the css to show/hide the ADD which you will used or call it when the user removes the item, then also call the same function that toggles this when another part is added in a different category.

Hope that helps you.

commented: As I read this post, I found it to be very helpful. Thank you for posting it. I enjoyed reading it. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.