Trying to open a new window using a tag using target attribute but it is not working. Here is my code:
<tr>
<td>
<?php echo $count;?>
</td>
<td><a class="oiu" href=<?php echo "eventdetail.php?idno=".$row[ 'E_id'];?>><u><?php echo $row['E_name'];?></u></a>
</td>
<td><a class="oiu" href=<?php echo "http://maps.google.com/maps?saddr=".$cadd. "&daddr=".$vadd;?> target="_blank" ><u><?php echo $row['Venue'];?><u></a>
</td>
<td>
<?php echo $row[ 'EDate']. ' '.$time;?>
</td>
<!-- <td><div id="remain"><?php echo "$days, $hours:$minutes:$seconds";?></div></td> -->
<td> <a class="icon1" href=<?php echo "update.php?idno=".$eid;?>><span class="glyphicon glyphicon-pencil pencil"></span></a><a class="icon2" href="#myModal2" data-toggle="modal"><span class="glyphicon glyphicon-trash trash"></span></a>
</td>
</tr>
<?php $count++;
Make your target="_blank" first then give your href="link" as given below and close the underline tag </u>.
Try the following code:
<tr>
<td><?php echo $count;?></td>
<td ><a class="oiu" href=<?php echo "eventdetail.php?idno=".$row['E_id'];?>><u><?php echo $row['E_name'];?></u></a></td>
<td><a class="oiu" target="_blank" href=<?php echo "http://maps.google.com/maps?saddr=".$cadd."&daddr=".$vadd;?> ><u><?php echo $row['Venue'];?></u></a></td>
<td><?php echo $row['EDate'].' '.$time;?></td>
<!-- <td><div id="remain"><?php echo "$days, $hours:$minutes:$seconds";?></div></td> -->
<td> <a class="icon1" href=<?php echo "update.php?idno=".$eid;?>><span class="glyphicon glyphicon-pencil pencil"></span></a><a class="icon2" href="#myModal2" data-toggle="modal"><span class="glyphicon glyphicon-trash trash"></span></a></td>
</tr>
Related
I'm trying to send player id to delete and update page and it doesn't send it.
i'm adding my table body here.
<tr>
<td><img src="<?php echo $readRow['Photo']; ?>" width='64px'></td>
<td> <?php echo$readRow['ID']; ?></td>
<td> <?php echo$readRow['Fname']; ?></td>
<td> <?php echo $readRow['Lname']; ?></td>
<td> <?php echo$readRow['Age']; ?></td>
<td> <?php echo$readRow['Email']; ?></td>
<td> <?php echo$readRow['Phone']; ?></td>
<td><a href='update.php?id=$readRow[ID]' data-toggle="modal" data-
target="#editplayer" class = 'btn btn-success'>Edit</a>
<a href="delete.php" name = "Delete" class = 'btn btn-danger'>Delete</a></td>
</tr>
<?php
}
?>
please help.
You need <?php echo ?> around $readRow[ID]. And you need to put that into the delete.php URL as well.
<tr>
<td><img src="<?php echo $readRow['Photo']; ?>" width='64px'></td>
<td> <?php echo$readRow['ID']; ?></td>
<td> <?php echo$readRow['Fname']; ?></td>
<td> <?php echo $readRow['Lname']; ?></td>
<td> <?php echo$readRow['Age']; ?></td>
<td> <?php echo$readRow['Email']; ?></td>
<td> <?php echo$readRow['Phone']; ?></td>
<td><a href='update.php?id=<?php echo $readRow['ID']; ?>' data-toggle="modal" data-
target="#editplayer" class = 'btn btn-success'>Edit</a>
<a href="delete.php?id=<?php echo $readRow['ID']; ?>" name = "Delete" class = 'btn btn-danger'>Delete</a></td>
</tr>
<?php
}
?>
You can just add your id to be deleted as a GET parameter
<a href="delete.php?id=<?php echo $readRow['ID']; ?>" name = "Delete" class = 'btn btn-danger'>Delete</a></td>
However, I suggest you stay away from GET and use POST method, which is much more secure.
<form action="delete.php" method="post">
<tr>
<td><img src="<?php echo $readRow['Photo']; ?>" width='64px'>
// ...other td elements
</tr>
</form>
You need to enclose player id with <?php and ?> (PHP start and end tag respectively) as given below:
<a href="update.php?id=<?php echo $readRow['ID']; ?>" data-toggle="modal" data-target="#editplayer" class = 'btn btn-success'>Edit</a>
<a href="delete.php?id=<?php echo $readRow['ID']; ?>" name = "Delete" class = 'btn btn-danger'>Delete</a>
I'm creating a table using ajax and php but there's one problem, the table isn't showing in my div. I'm really new to ajax so I don't really fully understand it yet.
Here's my div:
<div class="body" id="live-data">
</div>
Here's the ajax code:
$(document).ready( function() {
function fetch_data() {
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data){
$('#live_data').html(data);
}
});
}
fetch_data();
});
And here's fetch.php:
<?php
include('../global/db.php');
$output = '';
$sql ="SELECT * FROM students WHERE status = '0' AND stud_grade = '$level_id' ORDER BY date_enrolled DESC";
$result = mysqli_query($db, $sql);
$output .= '
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th width="135" class="noExport">Action</th>
<th width="90">LRN</th>
<th width="20">Level</th>
<th>Name</th>
<th width="20">Gender</th>
<th width="60">Type</th>
<th width="105" style="font-size: 14px!important;">Date Enrolled</th>
</tr>
</thead>
<tbody>';
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)){
$output .= '
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
';
}
}
else {
$output .= '
<tr>
<td colspan="12">Data not Found</td>
</tr>';
}
$output .= '
</tbody>
</table>
</div>';
echo $output;
?>
It would great if anyone could help because I just don't know why it doesn't work
Edit:
I've changed the code so it returns the data in the console tab and here's what shows up:
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th width="135" class="noExport">Action</th>
<th width="90">LRN</th>
<th width="20">Level</th>
<th>Name</th>
<th width="20">Gender</th>
<th width="60">Type</th>
<th width="105" style="font-size: 14px!important;">Date Enrolled</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
</tbody>
</table>
</div>
So it clearly returns the correct data but it just doesn't show up in the live-data div
Maybe take a look in your html where is your div. Your div id says "live-data" and in the ajax code you mentioned to fetch data for div id "#live_data" instead of "#live-data".
Maybe changing them for same name can solve your problem. I would use for thr div id and in the ajax same id names like "#liveData".
Example (same code, just edited to the right IDs, compare with your original):
Your HTML div
<div class="body" id="liveData">
</div>
Your ajax code
$(document).ready( function() {
function fetch_data() {
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data){
$('#liveData').html(data);
}
});
}
fetch_data();
});
Just append the correct Id of the div tag in sucess function
I'm trying to add DataTables to my webpage, but the DataTable isn't displaying as expected. In order to troubleshoot the issue, I copied the key contents into another PHP file (see code below) and it seems that it an error occurs whenever data is displayed into the table using the SELECT SQL query.
PHP code where it displays incorrectly. See this image for context.
<?php
include 'includes/config.inc.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta meta name="viewport" content ="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content ="ie=edge">
<title>Troubleshoot page</title>
</head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
<body>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Theme</th>
<th>Visual Idea</th>
<th>Caption</th>
<th>Date</th>
<th>Visual</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$table = mysqli_query($conn ,"SELECT * FROM content WHERE uidCompany='" . $_SESSION[ "userCid" ] . "'");
while($row = mysqli_fetch_array($table)){ ?>
<tr id="<?php echo $row['uidContent']; ?>">
<td style = "display:none" data-target="uidContent"><?php echo $row['uidContent']; ?></td>
<td width="200" data-target="themeContent"><?php echo $row['themeContent']; ?></td>
<td width="300" data-target="visualIdeaContent"><?php echo $row['visualIdeaContent']; ?></td>
<td width="600" data-target="captionContent"><?php echo $row['captionContent']; ?></td>
<td width="100" data-target="dateContent"><?php echo $row['dateContent']; ?></td>
<td><img src="<?php echo $row['visualContent']; ?>"width="100"/></td>
<td style = "display:none" width="100" data-target="linkContent"><?php echo $row['linkContent']; ?></td>
<td style = "display:none" width="100" data-target="visualContent"><?php echo $row['visualContent']; ?></td>
<td width="170">
<a class="badge badge-primary p-2" role="button" href="<?php echo $row['linkContent']; ?>" rel=“external”>Link</a>
<a class="badge badge-success p-2 text-white" href="#" data-toggle="modal" data-target="#updatePostModal" data-role="update" data-id="<?php echo $row['uidContent']; ?>">Edit</a>
<a class="badge badge-danger p-2" role="button" href="includes/action.inc.php?delete=<?php echo $row['uidContent'] ;?>" onclick="return confirm('Are you sure you want to delete this post? This process cannot be undone.');">Delete</a>
</td>
</tr>
<?php }
?>
</tbody>
</table>
</body>
<script>
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</html>
PHP code where it displays correctly. See this image for context.
<?php
$title = "My Calendar";
include 'includes/config.inc.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta meta name="viewport" content ="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content ="ie=edge">
<title>Title</title>
</head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
<body>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Theme</th>
<th>Visual Idea</th>
<th>Caption</th>
<th>Date</th>
<th>Visual</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>This is</td>
<td>Some Example</td>
<td>Data</td>
<td>2019-08-08</td>
<td>image here</td>
<td>
<a class="badge badge-primary p-2" role="button" href="<?php echo $row['linkContent']; ?>" rel=“external”>Link</a>
<a class="badge badge-success p-2 text-white" href="#" data-toggle="modal" data-target="#updatePostModal" data-role="update" data-id="<?php echo $row['uidContent']; ?>">Edit</a>
<a class="badge badge-danger p-2" role="button" href="includes/action.inc.php?delete=<?php echo $row['uidContent'] ;?>" onclick="return confirm('Are you sure you want to delete this post? This process cannot be undone.');">Delete</a>
</td>
</tr>
<tr>
<td>This is</td>
<td>Some More</td>
<td>Sample Data</td>
<td>2019-08-08</td>
<td>image here</td>
<td>
<a class="badge badge-primary p-2" role="button" href="<?php echo $row['linkContent']; ?>" rel=“external”>Link</a>
<a class="badge badge-success p-2 text-white" href="#" data-toggle="modal" data-target="#updatePostModal" data-role="update" data-id="<?php echo $row['uidContent']; ?>">Edit</a>
<a class="badge badge-danger p-2" role="button" href="includes/action.inc.php?delete=<?php echo $row['uidContent'] ;?>" onclick="return confirm('Are you sure you want to delete this post? This process cannot be undone.');">Delete</a>
</td>
</tr>
<tr>
<td>This is</td>
<td>Another row</td>
<td>Of sample data</td>
<td>2019-08-08</td>
<td>image here</td>
<td>
<a class="badge badge-primary p-2" role="button" href="<?php echo $row['linkContent']; ?>" rel=“external”>Link</a>
<a class="badge badge-success p-2 text-white" href="#" data-toggle="modal" data-target="#updatePostModal" data-role="update" data-id="<?php echo $row['uidContent']; ?>">Edit</a>
<a class="badge badge-danger p-2" role="button" href="includes/action.inc.php?delete=<?php echo $row['uidContent'] ;?>" onclick="return confirm('Are you sure you want to delete this post? This process cannot be undone.');">Delete</a>
</td>
</tr>
</tbody>
</table>
</body>
<script>
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</html>
What's wrong with the first set of code?
Problem inside <tbody></tbody> code. You have added more <td> then <th>.
You have to remove all <td style = "display:none">. You have 6 header and every row must contain exactly same number of <td>.
<tbody>
<?php
$table = mysqli_query($conn ,"SELECT * FROM content WHERE uidCompany='" . $_SESSION[ "userCid" ] . "'");
while($row = mysqli_fetch_array($table)){ ?>
<tr id="<?php echo $row['uidContent']; ?>">
<td width="200" data-target="themeContent"><?php echo $row['themeContent']; ?></td>
<td width="300" data-target="visualIdeaContent"><?php echo $row['visualIdeaContent']; ?></td>
<td width="600" data-target="captionContent"><?php echo $row['captionContent']; ?></td>
<td width="100" data-target="dateContent"><?php echo $row['dateContent']; ?></td>
<td><img src="<?php echo $row['visualContent']; ?>"width="100"/></td>
<td width="170">
<a class="badge badge-primary p-2" role="button" href="<?php echo $row['linkContent']; ?>" rel=“external”>Link</a>
<a class="badge badge-success p-2 text-white" href="#" data-toggle="modal" data-target="#updatePostModal" data-role="update" data-id="<?php echo $row['uidContent']; ?>">Edit</a>
<a class="badge badge-danger p-2" role="button" href="includes/action.inc.php?delete=<?php echo $row['uidContent'] ;?>" onclick="return confirm('Are you sure you want to delete this post? This process cannot be undone.');">Delete</a>
</td>
</tr>
<?php }
?>
</tbody>
You are loading datatable js before Jquery library in PHP code page.
Load js and css in below order, it should work.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap4.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/dataTables.bootstrap4.min.js"></script>
My delete button is not working.
For a view file it's working - this is my code for view_file.php:
<?php
$sql_id="SELECT * FROM meeting_info where id=".$id ;
`$result2 = $conn->query($sql_id);
if($row2 = $result2->fetch_assoc()) {
$bilno = $row2['bilno'];
}
?>
<body>
<div id="body">
<table align="center" width="90%">
<tr>
<th colspan="6">
<div align="center">
<h3>Meeting Bil.No
<?php echo $bilno; ?> </h3>
</div>
</th>
</tr>
<tr bgcolor="#3366ff">
<td>Bil. Item</td>
<td>File Type</td>
<td>File Size (KB)</td>
<td>View</td>
<td>Edit</td>
<td>Delete</td>
</tr>
<?php
$sql="SELECT * FROM meeting_details where id=".$id ." order by item_no asc";
$result = $conn->query($sql);
while($row = $result->fetch_assoc())
{
if($j%2 == 1) {$colortd = "#99ccff";
}
else {$colortd = "#f5f5f0";}
?>
<tr bgcolor=<?php echo $colortd;?>>
<td>
<?php echo $row['item_no'] ?>
</td>
<td>
<?php echo $row['type'] ?>
</td>
<td>
<?php echo $row['size'] ?>
</td>
<td>
<a class="btn btn-view" href="uploads/<?php echo $row['file']; ?>" target="_blank" alt="<?php echo $row['item_no']; ?>" title="click for edit">
<center><img src="images\iconview.png"></center>
</a>
</td>
<td>
<a class="btn btn-info" href="edit_file.php?edit=<?php echo $row['id']; ?>" title="click for edit" onclick="return confirm('sure to edit ?')">
<center><img src="images\iconedit.png"></center>
</td>
<td>
<a class="btn btn-danger" href="delete_file.php?delete=<?php echo $row['id']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')">
<center><img src="images\icondel.png"></center>
</td>
</tr>
<?php
$j++;
}
//$conn->close();
?>
</table>
</div>
</body>
For the delete button, I want to delete all rows on information that I want to delete. But it's not working. When i click the delete button it's just come out the blank page. The data still have in database and website.
This my delete_file.php code:
<?php
include("db_conn.php");
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
$id =$_GET['id'];
$sql = "DELETE FROM meeting_details WHERE id=".$id;
$result = $conn->query($sql);
}
$conn->close();
?>
Check this line:
<a class="btn btn-danger" href="delete_file.php?delete=<?php echo $row['id']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')">
here the delete url is like: delete_file.php?delete=1 and you are fetching the value like:
$id =$_GET['id'];
So change it to:
$id =$_GET['delete'];
and try again.
Note: Your code is wide open to SQL injection
HTML structure:
<tr>
<td><div class="img ico-networking" title="Tinklalapis"></div></td>
<td>Tinklalapis</td>
<td>
http://www.servit.lt <a title="Informacija apie svetainę servit.lt" href="http://www.ooo.lt/svetaine/google.lt" class="infoAboutSite iconInfo" target="_blank"></a> <a title="Įmonės svetainė servit.lt" href="google.com" class="infoAboutSite siteScreenshot iconWww" target="_blank"></a> </td>
</tr>
My PHP selector: $tr->children[2]->find('a',0)->href;
I'm getting empty string, what is wrong with my selector ?
I think this code that helps you
<?php
$help1 = '<tr>
<td><div class="img ico-networking" title="Tinklalapis"></div></td>
<td>Tinklalapis</td>
<td>
http://www.servit.lt <a title="Informacija apie svetainę servit.lt" href="http://www.ooo.lt/svetaine/google.lt" class="infoAboutSite iconInfo" target="_blank"></a> <a title="Įmonės svetainė servit.lt" href="google.com" class="infoAboutSite siteScreenshot iconWww" target="_blank"></a> </td>
</tr>';
include "simplehtmldom_1_5/simple_html_dom.php";
$help2 = str_get_html($help1);
echo $help2->find('a',0)->href ;
?>