1

I have a page displaying data from an array. When the user click on one of the picture displayed, I would need to save the value $row["Rif"] as I'd need to display the item details in another page.

I was looking around but it seems that Jquery, Ajax are the only available solutions but I don't know these.

Is there any way to implement it using just PHP?

Thank you!

 <?php
          if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo "<div class='col-md-3 col-sm-6 col-xs-12'>
                            <div class='property-container'>
                              <div class='property-image'>
                                <img src='img/img02.jpg' alt='test theme'>
                                <div class='property-price'>
                                  " . $row["DescCom"] . "<br>
                                  <span>" . "€ ". $row["Pre"] . " </span>
                                </div>
                                <div class='property-status'>
                                  <span>" . $row["Rif"] . "</span>
                                </div>
                              </div>
                              <div class='property-features'>
                                <span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
                                <span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
                                <span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
                              </div>
                              <div class='property-content'>
                                <h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
                                <button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
                              </div>
                            </div>
                          </div>";
                }
            } else {
                echo '0 results';
            }
            $conn->close();
        ?>
3
  • why dont you carry the id of the product to next page and fetch the entire details there again? Commented Feb 25, 2016 at 11:39
  • Hi Fakhruddin, the while loop is displaying many results how do I know which ID to carry ? I should carry just the one clicked actually Thanks Commented Feb 25, 2016 at 11:42
  • did you get it working? Commented Feb 25, 2016 at 11:53

1 Answer 1

1

Assuming the data is stored in $row["Rif"]

<?php
          if ($result->num_rows > 0) {
                // output data of each row
                while($row = $result->fetch_assoc()) {
                    echo "<div class='col-md-3 col-sm-6 col-xs-12'>
                            <div class='property-container'>
                              <div class='property-image'>

 // if this is the image you can hyper-link it to next page that will carry the id as well.

                              <a href='next_page.php?id=". $row['Rif']."><img src='img/img02.jpg' alt='test theme'></a>
                                <div class='property-price'>
                                  " . $row["DescCom"] . "<br>
                                  <span>" . "€ ". $row["Pre"] . " </span>
                                </div>
                                <div class='property-status'>
                                  <span>" . $row["Rif"] . "</span>
                                </div>
                              </div>
                              <div class='property-features'>
                                <span><i class='fa fa-home'></i> " . $row["Mq"] . " m<sup>2</sup></span>
                                <span><i class='fa fa-hdd-o'></i> " . $row["Cam"] . " Cam</span>
                                <span><i class='fa fa-male'></i> Piano " . $row["Pia"] . " </span>
                              </div>
                              <div class='property-content'>
                                <h3>" . $row["TIP"] . "<small>" . $row["Fra"] . "</small></h3>
                                <button type='submit' name='submit' class='btn btn-default btn-warning btn-xs pull-right btn-dettagli'>Details</button>
                              </div>
                            </div>
                          </div>";
                }
            } else {
                echo '0 results';
            }
            $conn->close();
        ?>

if this is the image you can hyper-link it to next page that will carry the id as well.

<a href='next_page.php?id=". $row['Rif']."><img src='img/img02.jpg' alt='test theme'></a>
Sign up to request clarification or add additional context in comments.

7 Comments

Hi, thanks for that I think there is a problem with the quotes,if I leave it like that it doesn't work but even if I change to single quotes it doesn't, not sure how to embed your change in it Thanks
@ChrisA updated my answer. I had missed out echo. Let me know if it works out.
Hi, just tried but it's not working, the problem is that it doesn't accept the double quotes we are using in the <a> tag as it's inside an echo. If I change with single quotes it gives me quotes error again on the same line Thank you
@ChrisA sorry I missed out that you were implementing it in PHP. Corrected the answer.
Hi works!! Sorry to bother, last question, where is this value stored? I tried to echo $_GET['Rif'] in "next_page.php" but it's not set Thanks a lot
|

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.