Cannot pass javascript variable to php page under jquery .click() method -
in code below window.location.href
not working. when use outside .click
function works inside not.
<script> $('#para').click(function(e) { var getid= $("#"+e.target.id).text(); id = getid.substring(getid.indexof("id: ")+3,getid.length); alert ("success"); window.location.href = "specificimagepage.php?id=" + id; } </script>
the below code (just showing para id is) used retrieve images database , when user clicks on image want pass image id next page, can again used.
<div id = "para"> <?php $j; $files = glob("upload/*.*"); require 'config.php'; //database config file ($i=0; $i<count($files); $i++) { $image = $files[$i]; $info = pathinfo($image); $file_name = basename($image); $sql = "select id,address, cuisine, imagename postfood imagename = '".$file_name."' "; $result = mysqli_query($con, $sql); echo "filename is".$file_name; echo (mysqli_num_rows($result)); if (mysqli_num_rows($result) > 0) { $row; while($row = mysqli_fetch_assoc($result)) { echo '<div id = '.$j.' style="float:left;margin:2.5em;"><a href = "" ><img src="'.$image .'" alt="random image" id = '.$j.' width="250em" height="250em"/>'. "<br>address: " . $row["address"]. "<br> -cuisine: " . $row["cuisine"]. "<br> -imagename: " . $row["imagename"]."<br> -id: " . $row["id"]. '</a></div>'; ++$j; ?> </div>
the code specificimagepage.php is:
<?php if(isset($_get["id"])) { $uid = $_get["id"]; } else { echo ("no "); } ?> <?php if(isset($_get["id"])) { $uid = $_get["id"]; } else { echo ("no "); } ?>
the problem anchor tag in echo statement
echo '<div id = '.$j.' style="float:left;margin:2.5em;"><a href = "" ><img src="'.$image .'" alt="random image" id = '.$j.' width="250em" height="250em"/>'. "<br>address: " . $row["address"]. "<br> -cuisine: " . $row["cuisin.....
deleted anchor tag in above code , able pass variable
Comments
Post a Comment