I have a find_all () function, which is written in a separate file:
public static function find_all() { return self::find_by_sql("SELECT * FROM ".self::$table_name); }
It was listed at the top of the file, which includes my foreach loop:
<?php require_once("../../includes/initialize.php"); ?> <?php if (!$session->is_logged_in()) { redirect_to("login.php"); } ?> <?php $parents = UserParent::find_all(); ?>
This is the foreach loop:
<?php foreach($parents as $parent): ?> <div class='popup-screen' id = "popup"> <div class = "spacing"> Do you want to delete this data? </div> <a href="list_users.php?parentNum=<?php echo $parent->parentNum; ?>"> <input type="button" value="YES" class = "popup-button"> </a> <input type="button" value="CANCEL" class = "popup-button" onClick = "hide();"> </div> <tr class = "tr-1"> <td onClick = "document.location = 'viewParent.php?parentNum=<?php echo $parent->parentNum; ?>';"><img src="../<?php echo $parent->image_path(); ?>" width="100" height = "100" class = "profile-pic"/></td> <td onClick = "document.location = 'viewParent.php?parentNum=<?php echo $parent->parentNum; ?>';">Parent</td> <td onClick = "document.location = 'viewParent.php?parentNum=<?php echo $parent->parentNum; ?>';"><?php echo $parent->username; ?></td> <td onClick = "document.location = 'viewParent.php?parentNum=<?php echo $parent->parentNum; ?>';"><?php echo ucwords($parent->firstName); ?></td> <td onClick = "document.location = 'viewParent.php?parentNum=<?php echo $parent->parentNum; ?>';"><?php echo ucwords($parent->lastName); ?></td> <td onClick = "show();"><img src = "../stylesheets/images2/delete-icon.png" height="25" width="25" ></td> </tr> <?php endforeach; ?>
And this is the javascript code:
function show() { document.getElementById("popup").style.display='block'; } function hide(){ document.getElementById("popup").style.display='none'; }
Basically, my code is creating lines of information that gets its data from the foreach loop. At the end of each line is a delete icon, as shown by the img tag. After clicking on the delete icon, the show () function will be launched (the show () function only shows a pop-up window that is invisible) - confirmation of whether the user wants to delete his data or not. If the user clicks the CANCEL button, the window will close as shown by the javascript code. If the user clicks "YES", SUPPOSED goes to the link: list_users.php? ParentNum = parentNum ;? > (The value of $ parent-> parentNum is different for each row). However, the linked ALWAYS tag retrieves the link for the first line, regardless of whether it is the third line or something (by the way, links to other td tags work). Now, to my question, how to properly link the YES button for each row in a popup div?
Yourmom
source share