javascript - Send PHP Link data from ajax call to different page onclick -


im busy learning ajax. have reservation page , checkout page.

what want do

user types renter name search box, matching names gets fetched db , displayed dynamically.

like so:

reservations.php

enter image description here

when user clicks highlighted link, reservation id passed checkout page. thus, im looking way pass reservation id another/different page, can use data processing on checkout page.

checkout.php

enter image description here

code

search / jquery

$(document).ready(function () {         $("#searchbox").on('keyup',function () {             var key = $(this).val();              $.ajax({                 url:'fetch.php',                 type:'get',                 data:'keyword='+key,                 beforesend:function () {                     $("#results").slideup('fast');                 },                 success:function (data) {                     $("#results").html(data);                     $("#results").slidedown('fast');                 }             });         });     }); </script> <div id="main">     <div id="header"><h1>find names</h1></div>     <div id="content">         <input type="search" name="keyword" placeholder="search names" id="searchbox">         <div id="results"></div>     </div> </div> 

fetch.php

  if($_get['keyword'] && !empty($_get['keyword']))     {         $conn = mysqli_connect('localhost','root','','*****'); //connection database         $keyword = $_get['keyword'];         $keyword="%$keyword%";         $query = "select renter_name reservations renter_name ?";         $statement = $conn->prepare($query);         $statement->bind_param('s',$keyword);         $statement->execute();         $statement->store_result();         if($statement->num_rows() == 0) // if have 0 records acc. keyword display no records found         {             echo '<div id="item">ah snap...! no results found :/</div>';             $statement->close();             $conn->close();          }         else {             $statement->bind_result($name);             while ($statement->fetch()) //outputs records             {                 echo "<div id='item'>$name</div>";             };             $statement->close();             $conn->close();         };     }; 

db

enter image description here

any or advice in terms of implementation appreciated!

simply use links , queries. @ first echo link instead of div:

echo "<a href='yourpage.php?id=$name'>$name</a>"; 

and on page do:

<?php echo $_get[" id"]; ?> 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -