Jump to content

OnClick event not being set through loop


noelde

Recommended Posts

Hi - I'm new to the forum and php and could use some help.

 

I'm trying to correct the following erroneous code (excerpted below) and am hoping that I can be set straight. The problem I'm having is with the onclick event.

 

My hope was to have the href be assigned to the same page ("test_loop_hrefs.php") for each of the listed items, but when the user clicks a listed item, a session var ($_SESSION['recordid']) is set to a unique recordid ($row['prop_id']) that then determines the database content for the page.

 

The browser renders the hyperlinks in the bulleted list fine. But for the onclick event, the $_SESSION['recordid'] is set to the last $row['prop_id'] from the while loop for every hyperlink...please see below.

 

$tbl_name="tb_content";

$sql="SELECT * FROM $tbl_name order by price asc";

$result=mysql_query($sql);

 

echo "<ul>";

while($row=mysql_fetch_assoc($result)){

?>

<li><a href="test_loop_hrefs.php" onclick="<?php $_SESSION['recordid']= $row['prop_id']; ?>"><?php echo $row['address1']; ?></a></li>

<?php

} // End while loop.

echo "</ul>";

 

Thanks in advance for your much needed help!!

Link to comment
https://forums.phpfreaks.com/topic/44980-onclick-event-not-being-set-through-loop/
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.