Jump to content

Foreach Loop If Value


dsbpac

Recommended Posts

How do I do a value check for an foreach loop? What I'm trying to do is declair if product_id = 10 then do this action else do this inside of the foreach loop where the link is located.

Example

<?php

$product_id = $_GET['product_id'];

 

if ( $product_id == 10 ) {

echo "<a href="product_custom_1";

} else {

echo "<a href="product_details.php?product_id=<?php echo $row['product_id']; ?>">";<----- how do I pull the product id inside of foreach?

}

 

<form class="add_product" method="post" action="">
 <?php foreach ($products as $row): ?>
					    <li class="first">
						 <a href="product_details.php?product_id=<?php echo $row['product_id']; ?>">
   <?php if (is_null($row['product_thumbnail'])): ?>
    <img src="?image=no_image.png" width="160" height="200" alt="" />
   <?php else: ?>
    <img src="?image=<?php echo $row['product_thumbnail']; ?>" width="160" height="200" alt="" />
   <?php endif; ?>
  </a>
						    <div class="clear"></div>
						    <h6><center><?php echo $row['product_name']; ?></center></h6>
						    <div class="clear"></div>
						    <p><center>Unit Price: <?php echo price($row['product_price']); ?></center></p>
						    <div class="clear"></div>
<center><input type=button onclick="parent.location='product_details.php?product_id=<?php echo $row['product_id']; ?>'" class="buttonaddtocart2" value='Read More'>
</center>

					    </li>


 <?php endforeach; ?>

Link to comment
https://forums.phpfreaks.com/topic/272472-foreach-loop-if-value/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.