Loading php page using jquery/ajax to open specific links to display pages in a Div -


i have mysql table id/name/desc fields .i'm displaying in div using php select query

<div class="show_name">     while( $row = $data->fetch_array(mysqli_assoc))     { ?>         <div><?php echo $row['id'];?></div>         <div><?php echo $row['name'];?></div>     <?php } ?> </div> <div id="content"></div> 

jquery/ajax code

$('.show_name').on('click',function(){     $('#content').load('name.php'); }); 

i've name.php page want display description of clicked name link

for example id name 1   abc 2   xyz 

if click on abc name link should able open name.php abc desc

if click on xyz name link should able open same name.php xyz desc

etc..

please appricated thanks!

put class , user defined data attribute storing id

// add clickme class // , add data-id attribute <div class="clickme" data-id="<?php echo $row['id'];?>"><?php echo $row['id'];?></div> <div><?php echo $row['name'];?></div> 

then js code should :

// using on delegate dynamic element $('.show_name').on('click','.clickme', function(){   // capture data id   var id = $(this).data('id');   // load name.php , pass post parameter(id)   // pass id paramater here   // can use success callback if want populate   $('#content').load('name.php', {id : id});   // above code should display data name.php }); 

and inside name.php should have queries , html page :

// id pass load request earlier  $myid = $_post['id']; // logic here // query database details description using id = '$myid' // display content here // suppose have data store inside $mydata variable $mydata = getdata(); echo $mydata['name']; echo $mydata['desc']; 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -