Furkan Öksüz Furkan Öksüz - 5 months ago 12
SQL Question

How can i make every <p> tag clickable on a pop-up by using php?

as you can see my code is working with sql. Every email name
will be shown on a "pop up". And all of them will have separated p tag. What i am trying to make is when users click this p tag they must access another page. I am new to php and did something wrong . Some help would be great. Thanks.

<div id="dialog" title="Following">
<?php
$x=0;
$arrayName = array();
$sqls = "SELECT * FROM follow WHERE member_email='$email'";
$result = mysqli_query($conn,$sqls);
while($row = mysqli_fetch_assoc($result)) {
$arrayName[$x] = $row["person_email"];

$x=$x+1;
} ?>
<?php for($k = 0; $k < $x; $k++) {?>
<p id="pop" value="$arrayName[$k]" onclick="popFunc(this.value)"><?php echo $arrayName[$k]; ?></p>

</div>
/////////////////////////////////////////////////////////////////

function popFunc($element){

$_SESSION['visiter']=$element;
document.location.href = 'http://localhost/example/visiter.php';

}

Answer

You cannot mix Javascript and PHP in a function. Here is a solution

<div id="dialog" title="Following">
  <?php
  $x=0;
  $arrayName = array();
  $sqls = "SELECT * FROM follow WHERE member_email='$email'";
  $result = mysqli_query($conn,$sqls);
  while($row = mysqli_fetch_assoc($result)) {
    $arrayName[$x]  = $row["person_email"];

    $x=$x+1;
  } ?>
  <?php for($k = 0; $k < $x; $k++) {?>
    <p id="pop" onclick="popFunc('<?php echo  $arrayName[$k]; ?>')"><?php echo  $arrayName[$k]; ?></p>

  </div>
<?php } ?> 
/////////////////////////////////////////////////////////////////
<script>
function popFunc(element){
document.location.href = 'http://localhost/example/visiter.php?visiter='+element;
}
</script>

And your visiter.php:

Replace $_SESSION['visiter'] with $_GET['visiter']

Comments