0

I am using PHP and ASP.NET to pass variables over another page using a hyperlink. Bit of the code:

<h3><?php echo $product["01"]["model"]; ?></h3>
    <div class="image_box">
         <img src="images/product/01.jpg" alt="" />
    </div>
         <p><?php echo $product["01"]["brand"]; echo " "; echo $product["01"]["model"]; ?></p>
    </div></a>

So there is an image, the brand and the model displayed on the first page. When someone clicks that div, they are redirected to a new page called "product details" where they find all of the details of the product they've clicked on. This is done by ASP.NET (<a href="productdetail.aspx?brand=Jori&model=IceCube>). So here, the brand and the model are passed to the next page where I can use that data.

But is there a way I can replace <a href="productdetail.aspx?brand=Jori&model=IceCube> by <a href="productdetail.aspx?brand=$product["01"]["brand"]&model=$product["01"]["model"]> for example? So I don't have to write the brand and model every time but just get them from where I've made them.

This is how I made the products, it is in PHP:

$product = array(     "01" => array("brand" => "JORI", "model" => "Shiva"),
                      "02" => array("brand" => "JORI", "model" => "Espalda"),
                      "03" => array("brand" => "JORI", "model" => "Indy"));

1 Answer 1

1

My PHP is a little rusty but the following loop should do it for you.

<?php
    foreach($product as $p){
?>
<h3><?php echo $p["model"]; ?></h3>
<div class="image_box">
     <img src="images/product/<%php echo key($p); %>.jpg" alt="" />
</div>
     <p><a href="productdetail.aspx?brand=<?php echo $p["brand"]; ?>&model=<?php echo $p["model"]; ?>"><?php echo $p["brand"]; echo " "; echo $p["model"]; ?></a></p>
</div></a>
<?php
    }
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.