1


I have a slight dilemma on my hands. This is the situation. On a webpage, I am using a php while loop to read data into a page from a database. That works fine but I need each of this items when clicked, go to another webpage with more info on them. This 'more info' is just data that i will have on another column in database so its no biggie. So my dilemma is how do I know which item is clicked. Is there a way to track which unique index was clicked? (Keep in mind that I might me listing thousands of items on the page).

This is my while loop code

while($row = mysql_fetch_array($result)){
 echo '<div class="thumb">';
 echo '<a href="template.php"><img src='.$row['dresses_pic'].'/></a>';
 echo '<p>'.$row['price_'].'</p>';
 echo '</div>';
}

I have tried putting a SESSION inside the while loop but the next page always reads the last listing as the item.
Is there a better way to achieve what am trying to do?
Thanks

0

4 Answers 4

2

Just append the ID of the item to your link and then you can get it from the next page as a $_GET variable:

while($row = mysql_fetch_array($result)){
 echo '<div class="thumb">';
 echo '<a href="template.php?id='.$row['id'].'"><img src='.$row['dresses_pic'].'/></a>';
 echo '<p>'.$row['price_'].'</p>';
 echo '</div>';
}

template.php

$id = (int) $_GET['id']; // Use this to get the item from the DB
Sign up to request clarification or add additional context in comments.

6 Comments

I am trying to use this now does this code still work it does not seem to be working for me, could you help?
@littleswany Ask a new question and be sure to post the code you have written so far.
My question asking is blocked is there any other way?
@littleswany You just have to wait until the block is lifted.
how long does that take?
|
1

Try passing in the ID of the row item and THEN retrieve the data for that ID on the new page.

 echo '<a href="template.php?id='.$row['id'].'"><img src='.$row['dresses_pic'].'/></a>';

Comments

1

Pass the id of the record to the next page(Use url parameter is most simple, ?id=xxx), and query the db use the id (You could get it by $_GET['id']) to get the info.

Comments

1

Use a query string to pass the item ID to your template.php page.

while($row = mysql_fetch_array($result)){
 echo '<div class="thumb">';
 echo '<a href="template.php?id='.$row['item_id'].'"><img src='.$row['dresses_pic'].'/></a>';
 echo '<p>'.$row['price_'].'</p>';
 echo '</div>';
}

See altered line above...

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.