Unable to pass value of a row to another page in AJAX - php

I am having a table with 7 columns(Complaintid id,name,school name etc...) and also have button. When I click the button I need to pass the complaintid of that row to another page. pls help me find a way to pass the value.
<html>
<body>
<?php
include '../library/dbconnect.php';
$query="SELECT * FROM Complaint_register WHERE status=1 ORDER BY entrydate ";
$result=mysql_query($query) or die("Selection query of
Complaint_register is Error ".mysql_error());
$num = mysql_numrows($result);
$i=0;
$j=1;
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
$date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];
?>
<tr>
<td style="color: #000000"><?php echo $j;?></td>
<td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
<td style="color: #000000"><?php echo $entrydate;?></td>
<td style="color: #000000" ><?php echo $row[studname];?></td>
<td style="color: #000000"><?php echo $row[District];?></td>
<td style="color: #000000"><?php echo $row[School_name] ;?></td>
<td style="color: #000000"><?php
echo $row[Standard]."-".$row[Division];?></td>
<td id="disp" ><?php echo $row[Complaint];?></td>
<td id="button" name="viewbutton" >
</td>
</tr>
<?php
$button++;
$j=$j+1;
}
?>
</table>
</form>
</body>
</html>

Instead of using
<td id="button" name="viewbutton" >
</td>
use,
<td>
<input type="button" onclick="functionname(<?php echo $row[complain_Id]; ?>)">
</td>
and add a javascript function
<script>
function functioname(param)
{
window.location="redirectionpage?id="+param;
}
</script>
This will redirect to the page redirectionpage with the id.

Few Loop holes in your current attempt.
Strictly use mysqli or PDO instead of mysql as it's been deprecated.
It's mysql_num_rows not mysql_numrows.
Now coming to your problem, you can solve this by using jQuery ajax.
$("table").on("click","#button",function(){
var cid = $("#disp").text();
$.ajax({
type: "GET",
url: "anotherpage.php",
data: { complainid: cid},
success: function(data) {
alert(data) //To check if response is success
}
});
});
anotherpage.php:
<?php
$cid = $_GET['complainid'];
?>

You can use a link with complain id like complaints.php?complainid=echo your value here
<td id="button" name="viewbutton" >
view complaint
</td>
and you can style that link like a button if needed.
In complaints.php page you can take the details of that complain with the id you passed.

Related

button to send multiple data to the database (php, ajax)

I send the data from the database to the screen with foreach.I do not see any results when I click the button.where do i make mistakes i ask you to help
<table class="table">
<thead class="thead-dark" align="center" >
<th >id</th>
<th >EğitimAdı</th>
<th >Adres</th>
<th >Onay </th>
</thead>
<tbody>
<form id="form1" action="" method="post">
<?php $i=1; foreach($dbb as $ac){ ; ?>
<tr align="center" >
<td > <?php echo $ac[0]; ?> </td>
<td > <?php echo $ac[1]; ?></td>
<td align="center"> <iframe width="360" height="115" src="<?php echo $ac[2]; ?>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen ></iframe></td>
<td >
<button type="button" value="<?php echo $ac[0]; ?>" id="gonder" onclick="gonder('this.val()')">İzledim</button>
</td>
</tr>
<?php $i++; } ?>
</form> <p></p>
</tbody>
</table>
gonder.js send to the database
function gonder(deger){
$.ajax({
type:"post",
url:"isleme.php",
data:deger,
success:function(cevap) {
$("p").text(cevap);
}
})
}
isleme.php to view the screen
<?php
$b=$_POST['deger'];
echo $b;
?>
First you're missing parentheses:
onclick="gonder" has to be onclick="gonder()"
Secondly variable "deger" is empty because #id doesn't exist, try changing to:
var deger = $("#gonder").val();
I noticed you are iterating and having same id for all the elements. Ideally id should be unique in each of the document.
You can do either of the below:
prepare and have unique id for each iterative element.
Try removing id element since you are not dependent on click using id.
Please let me know, if it helps?

get individual child value from parent tag using onclick method

I want to get individual table id value with the individual button click. and I got the table id value but it shows all table id value's like (1234... 10).
How to get the individual table value (like clicking the 3rd button -> get 3rd table id only).
I am using both PHP and HTML code together.
This is my code.
<table>
<tr>
<td><b>S.No</b></td>
<td><b>User Name</b></td>
<td><b>Post Title</b></td>
<td><b>Post Date</b></td>
</tr>
<?php
require_once('databaseconnection.php');
$query = "SELECT * FROM `userpost`";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<tr>
<td style="width: 5%;" id="td_id" value="<?php echo " {$row[ 'postid']} "; ?>">
<?php echo "{$row['postid']}"; ?>
</td>
<td style="width: 15%;" id="td_user">
<?php echo "{$row['postuser']}"; ?>
</td>
<td style="width: 65%;" id="td_title">
<?php echo "{$row['posttitle']}"; ?>
</td>
<td style="width: 10%;">
<?php echo "{$row['postdate']}"; ?>
</td>
<td style="width: 5%;"><input id="getpostid" type="submit" value="view" onclick="actiongetpostid();"></input>
</td>
</tr>
<?php
}
?>
</table>
<script type="text/javascript">
function actiongetpostid() {
var tdid = $('tr').children('#td_id').text();
alert(tdid);
}
</script>
HTML code:
This table will create dynamically.
<tr>
<td style="width: 5%;" id="td_id" value="1">1</td>
<td style="width: 15%;" id="td_user">rose</td>
<td style="width: 65%;" id="td_title">YII2 framwork for PHP</td>
<td style="width: 10%;">2016-02-12</td>
<td style="width: 5%;"><input id="getpostid" type="submit" value="view" onclick="actiongetpostid();"></input>
</td>
</tr>
<tr>
<td style="width: 5%;" id="td_id" value="2">2</td>
<td style="width: 15%;" id="td_user">rose</td>
<td style="width: 65%;" id="td_title">Angular JS</td>
<td style="width: 10%;">2016-02-12</td>
<td style="width: 5%;"><input id="getpostid" type="submit" value="view" onclick="actiongetpostid();"></input>
</td>
</tr>
<tr>
<td style="width: 5%;" id="td_id" value="3">3</td>
<td style="width: 15%;" id="td_user">murali</td>
<td style="width: 65%;" id="td_title">EXT JS</td>
<td style="width: 10%;">2016-02-12</td>
<td style="width: 5%;"><input id="getpostid" type="submit" value="view" onclick="actiongetpostid();"></input>
</td>
</tr>
I am using this code within "while" loop so how to solve this issue. Please help me.
Firstly, I'm not sure why you are using <input> tags if you are just wanting to display the data. Use <button> tags instead.
On this note I would change your button td to something like:
<td style="width: 5%;"><button class="getpostid">View</button>
Note the use of class="getpostid". The use of id would only apply to the first element with getpostid as IDs can only be used once.
Then using jQuery:
$(document).ready(function(){
$('.getpostid').click(function(){
var tdid = $(this).parents('tr').find('#td_id').text();
alert(tdid);
});
});
Note the use of parents() instead of parent(). The latter can only go up one level in the DOM tree. Whereas the step needed is 2 levels.
Here is a JSFiddle with a working example.

Displaying submitted form results as a list of URL links

First of all my PHP skills are kinda limited, Hence my question to you here.
I have built a fairly complex form with multiple inputs(text boxs and drop downs) which are stored in a MYsql DB. When the form is submitted it displays on a new page as completed reports. These completed reports display one under the next every time the form is submitted. My question is, How can i get the reports displayed to show as a list of links to the individual reports rather then a list of complete reports.
I hope i've explained the situation well enough.
Code snippit from viewpage.php
<html>
<head>
<body>
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
?>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div style="padding:15px 0px 0px 100px;">
<table cellpadding="0" cellspacing="0" border="0" style="vertical-align:middle;width: 1139px; background-color:#213568; height:36px;">
<tr>
<td class="topbar">Client Request Form</td>
<td style="width:900px;"></td>
<td class="topbar"><a style="color:#ffffff;" href="logout.php?logout">Logout</a></td>
</tr>
</table>
<div class="main-wrap">
<div class="content">
<table cellpadding="0" cellspacing="0" border="0" style="width: 1137px; background-color:#ffffff; height:5px;">
<tr>
<td></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" >
<tr>
<td style="vertical-align:top; width:5px;"></td>
<td style="vertical-align:top;"><?php include("includes/clientchoices.php"); ?></td>
<td style="vertical-align:top; padding:0px 5px 15px 5px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="vertical-align:top; width:1002px;"> <h1> Dashboard</h1></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#f5f5f5;"><h2>Job Request Form</h2></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#ffffff; height:5px;"> </td>
</tr>
<tr>
<td>
<div class="form">
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center>
</td>
</tr>
<tr>
<td>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Project Leader:</td><td class="answersa"><div class= "typesectiona"><?php echo ($row['project_leader'] ); ?></div></td>
<td class="headingsb">Contact Number:</td><td class="answersb"><div class= "typesectionb"><?php echo ($row['contact_number'] ); ?></div></td>
<td class="headingsc">Company Details:</td><td class="answersc"><div class= "typesectionc"><?php echo ($row['company_details'] ); ?></div></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings5">Contact Person On Site:</td><td class="answers5"><div class= "typesection5"><?php echo ($row['contactperson_onsite'] ); ?></div></td>
<td class="headings6">Contact Details:</td><td class="answers6"><div class= "typesection6"><?php echo ($row['contact_no'] ); ?></div></td>
<td class="headings7">Date:</td><td class="answers7"><div class= "typesection7"><?php echo ($row['date'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings1">Job/Order Number:</td><td class="answers1"><div class= "typesection1"><?php echo ($row['job_order_number'] ); ?></div></td>
<td class="headings2">Document Number:</td><td class="answers2"><div class= "typesection2"><?php echo ($row['doument_number'] ); ?></div></td>
<td class="headings3">QCP:</td><td class="answers3"><div class= "typesection3"><?php echo ($row['qcp'] ); ?></div></td>
<td class="headings4">Page No:</td><td class="answers4"><div class= "typesection4"><?php echo ($row['pageno'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15px"></td>
<td><a class="othersubmitsLink" href="actionpdf.php">Email to Spectra</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php
}
?>
</body>
</html>
You will need a separate PHP script for displaying a report based on a supplied ID. This separate script would look something like this:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
$jobrequest = $jobrequestResult->fetch_assoc();
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Note that I have used mysqli in this example, if this is unsuitable you can use the old-style mysql commands, but for many many reasons (security chief among them) I would strongly suggest against this.
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
$jobrequest = mysql_fetch_array($result);
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Save this page as "viewjobrequest.php" and you will be able to load a given job request's report by supplying the jobrequest ID as a parameter in the URL, like so:
http://address_of_site/viewjobrequest.php?jobrequest_id=X
Now you can automatically generate a list of links to these pages by looking up your complete set of jobrequests and iterating over them, but instead on outputting a full report, just output a link:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
?>
<ul>
<?php
while ($jobrequest = $jobrequestResult->fetch_assoc())
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
?>
<ul>
<?php
while ($jobrequest = mysql_fetch_assoc($result))
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Note: I have deliberately omitted large portions of your HTML, you can add as much extra HTML as you need, I've just offered the bare bones to get you started.
BY looking at your code, I can say, it's not problem with PHP, it's more like HOW you are showing the result after fetching from database,
you are running loop, started from here
<?php while ($row=mysql_fetch_array($result)){ ?>
and ends here
<?php}?>
So everything inside loop or in easy words inside these brackets {} repeating again and again with new row of result fetched from database, if you take view source of viewpage.php you will see that style css file <link rel="stylesheet" href="css/style.css" type="text/css" /> repeating, Imagine if you are fetching 10 rows of result, you are also loading css file 10 times.
So the answer (most probably the solution) of your question is;
Your mysql query
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
$totalrows = mysql_num_rows($result); //Check Total Number of Rows To Check if Data Exist or Not
?>
and then in your HTML, First check if there are any rows exist in database which match your WHERE clause in mysql query.
//Set an if else statement here so incase if no data exist.
<?php if($totalrows > 0) {
//If row(s) exist run your while loop here
<?php while ($row=mysql_fetch_array($result)){ ?>
//Show the result here from database
//Close your loop
<?php } ?>
//Close your if condition
<?php } else { ?>
//Display a message here if there is no data to show
//Close your else bracket
<?php } ?>
With above explaniation I adjusted your HTML to show the result in desired way;
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center></td>
</tr>
<tr>
<td>
<?php if($totalrows > 0) {
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Link to Report</td>
</tr>
<?php while ($row=mysql_fetch_array($result)){ ?>
<tr>
//You have to replace `nameoffile.php` with file in which you want to display report and correct this (as i assumed it) if it's wrong `$row['id']`
<td>Open Report</td>
</tr>
<?php } ?>
</table>
</div>
<?php } else { ?>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>There is No Result To Show</td>
</tr>
</table>
</div>
<?php } ?>
</td>
</tr>
</table>
Note: MySQL will soon be deprecated, consider start using MYSQLi or PDO

Unable to pass value from a row to another page in AJAX

I have a table with 7 columns(Complaintid id,name,school name etc...) and also have a button. When I click the button I need to pass the complaintid of that row to another page. The problem is that value is not passing in the ajax page.
<html>
<body>
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
$date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];
?>
<tr>
<td style="color: #000000"><?php echo $j;?></td>
<td style="color: #000000"><?php echo $row[complain_Id]; ?> </td>
<td style="color: #000000"><?php echo $entrydate;?></td>
<td style="color: #000000" ><?php echo $row[studname];?></td>
<td style="color: #000000"><?php echo $row[District];?></td>
<td style="color: #000000"><?php echo $row[School_name] ;?></td>
<td style="color: #000000"><?php echo $ row[Standard]."-".$row[Division];?></td>
<td id="disp" ><?php echo $row[Complaint];?></td>
<td id="button" name="viewbutton" >
<input type="button" value="View" class="button" id="'<?php $button; ?>'" onclick="selectedjob(alert('hi there')<?php $job_id ?>)">
</td>
</tr>
<?php
$button++;
$j=$j+1;
}
?>
<input type='hidden' value='view' class='button' name="selectedjob" id="selectedjob">
</table>
</form>
<script type="text/javascript">
function selectjob(jobid)
{
$('#selectedjob').val(jobid);
$('#frmSelectJob').attr('action', 'careers-apply.php');
$('#frmSelectJob').attr('method', 'post');
$('#frmSelectJob').submit();
}
</body>
</html>
Try this. You need to echo
<input type="button" value="View" class="button" id="'<?php echo $button; ?>'" onclick="selectedjob(<?php echo $job_id; ?>)">
EDIT
You can pass the jobid as like this
function selectjob(jobid)
{
window.location.href = "display.php?jobid=" + jobid;
}
get the job id in display.php as $_GET['jobid']
You can do it by using jquery. I write simple code for you. I try it. It should work
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" >
jQuery(document).ready(function(){
<?php
// $num_rows=mysql_num_rows(query result)
$num_rows=10;
for($i=1;$i<$num_rows+1;$i++)
{
?>
$("#button_<?=$i?>").click(function(){
//alert("hi");
var complain_Id = $("#complain_Id_<?=$i?>").val();
if($("#complain_Id_<?=$i?>").val()=='') complain_Id="";
var dataString = 'complain_Id='+ complain_Id;
$.ajax({
type: "POST",
url: "getresult.php",
data: dataString,
success: function(msg){
$('#count_display').html(msg);
}
}); //END $.ajax
});
<?php
}
?>
});
</script>
<html>
<body>
<?php
?>
<form action="" name="frmcomplaint" id="frmcomplaint" method="post">
<table border="1" style="border-color: #FFFFFF;" >
<tr>
<th style="color: #FF0000">Sl. No</th>
<th style="color: #FF0000">Complaint Id</th>
<th style="color: #FF0000">Date</th>
<th style="color: #FF0000; width:200px;" >Name Of student</th>
<th style="color: #FF0000">District</th>
<th style="color: #FF0000">School Name</th>
<th style="color: #FF0000">Standard with </th>
<th style="color: #FF0000; width:200px;">Complaint</th>
</tr>
<?php
$button=1;
//while($row=mysql_fetch_array($result))
for($i=1;$i<11;$i++)
{
/* $date1=explode('-', $row[$i+2]);
$entrydate=$date1[2]."-".$date1[1]."-".$date1[0];
$job_id=$row[$i+1];*/
?>
<tr>
<td style="color: #000000" ><?php echo $i;?></td>
<td style="color: #000000" id="comid"><?php echo $i; ?>
<input type="hidden" name="complain_Id_<?=$i?>" id="complain_Id_<?=$i?>" value="<?=$i?>"/> </td>
<td style="color: #000000"><?php echo $i+2;?></td>
<td style="color: #000000"><?php echo $i+3;?></td>
<td style="color: #000000"><?php echo $i+4;?></td>
<td style="color: #000000"><?php echo $i+5;?></td>
<td style="color: #000000"><?php echo $i+6;?></td>
<td id="disp" ><?php echo $i+7;?></td>
<td id="button" name="viewbutton" >
<input type="button" value="View" class="button_<?=$i?>" id="button_<?=$i?>" />
</td>
</tr>
<?php
//$button++;
//$j=$j+1;
}
?>
</table>
</form>
<div id="count_display" >
</div>
</body>
</html>
code for display.php
<?php
$complain_Id=$_POST['complain_Id'];
echo "complain_Id=".$complain_Id;
?>
Please change code as your need. I use a hidden input field to hold complain_Id value

open a div having id using onclick in a hyperlink

below is the given div having id "panel" and links in the same page but outside this div, when I click on the link this div should be open. there are several links so jquery does not work and my button is created dynamically through php while loop hence i cannot put unique id in my hyperlink
<div id="panel">
<form name="userloginform" action="xxx.php" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="tb">
<tr>
<td align="left" valign="middle" height="80">User Name</td>
<td align="left" valign="middle">: </td>
<td align="left" valign="middle"><input name="user" type="text" class="log"/></td>
</tr>
<tr>
<td align="left" valign="middle">Password</td>
<td align="left" valign="middle">: </td>
<td align="left" valign="middle"><input name="pass" type="password" class="log"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="3"><input name="submit1" type="submit" value="Login" class="login_btn"/></td>
</tr>
</table>
</form>
</div>
and my link is
<a href="#" id="flip" >Launch Now</a>
<a href="#" id="" >Launch Now</a>
If I am not clear please reply which part is not clear so that I can edit and provide useful information clearly
ok here is where link is coming from, a CMS is used here.
<?php
$sql=mysql_query("SELECT * FROM heading ORDER BY id DESC");
while($r=mysql_fetch_array($sql))
{
$ii=$r['id'];
?>
<h3><?php echo $r['heading'];?></h3>
<div>
<div class="content">
<div class="main_table_wrapper">
<table width="1030" border="0" cellspacing="0" cellpadding="0" align="left">
<?php
$sql2=mysql_query("SELECT * FROM inner_table WHERE head='$ii'") ;
while($rows=mysql_fetch_array($sql2))
{
$abc=str_replace($rows['url'],'XXXXXXXXXXXXXXX',$rows['url']);
?>
<tr>
<th align="left" valign="middle" width="350"><?php echo $rows['inner_names'];?></th>
<th align="left" valign="middle" width="250"><?php echo $abc;?></th>
<th align="left" valign="middle" width="200"><?php echo $rows['author'];?></th>
<th align="center" valign="middle" width="100"><?php echo $rows['doe'];?></th>
<th align="right" valign="middle" width="130"><span class="lunch">Launch Now</span></th>
</tr>
<?php } ?>
</table>
</div>
</div>
</div>
<?php } ?>
</div>
You can't have multiple elements with the same id.
Since you didn't show any JS code so far, the only advice I can give is to use a class as the identifier for the action link.
From the look of your markup you could also use something along
$('span.lunch').on('click', 'a', function(e) { //do stuff } );

Categories