Delete comments codeigniter with ID and user - codeigniter

how to delete comments with codeigniter, remove users based post_id ??
example :
i want delete comment (tester2) with user(admin) post_id (1)
this tables my database
<table width="540" height="66" border="1" >
<tr>
<td><div align="center"><strong>post_id</strong></div></td>
<td><div align="center"><strong>id_alat</strong></div></td>
<td><div align="center"><strong>user</strong></div></td>
<td><div align="center"><strong>namaalat</strong></div></td>
<td><div align="center"><strong>commnet</strong></div></td>
<td><div align="center"><strong>input_date</strong></div></td>
</tr>
<tr>
<td><div align="center">1</div></td>
<td><div align="center">001</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat1</div></td>
<td><div align="center">tester1</div></td>
<td><div align="center">08/09/2015</div></td>
</tr>
<tr>
<td><div align="center">2</div></td>
<td><div align="center">002</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat2</div></td>
<td><div align="center">tester2</div></td>
<td><div align="center">08/09/2015</div></td>
</tr>
</table>

View,
<table width="540" height="66" border="1" >
<tr>
<td><div align="center"><strong>post_id</strong></div></td>
<td><div align="center"><strong>id_alat</strong></div></td>
<td><div align="center"><strong>user</strong></div></td>
<td><div align="center"><strong>namaalat</strong></div></td>
<td><div align="center"><strong>commnet</strong></div></td>
<td><div align="center"><strong>input_date</strong></div></td>
<td><div align="center"><strong>Action</strong></div></td>
</tr>
<tr>
<td><div align="center">1</div></td>
<td><div align="center">001</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat1</div></td>
<td><div align="center">tester1</div></td>
<td><div align="center">08/09/2015</div></td>
<td><div align="center"><button>Delete</button></div></td>
</tr>
<tr>
<td><div align="center">2</div></td>
<td><div align="center">002</div></td>
<td><div align="center">admin</div></td>
<td><div align="center">alat2</div></td>
<td><div align="center">tester2</div></td>
<td><div align="center">08/09/2015</div></td>
<td><div align="center"><button>Delete</button></div></td>
</tr>
</table>
at Controller,
public function controller_function(){
$id= $_GET['id'];
$user = $_GET['user'];
if($user == "admin"){
$this->load->model('model_name/model_function');
$data = $this->model_function->delete_comment($id);
if(data == true){
echo "Deleted Successfully";
}
}
}
At model,
public function delete_comment($id){
$this->db->where('post_id',$id);
$sql = $this->db->delete('Your_Comment_Table_Name');
($sql)? return TRUE : return False;
}
I hope this will help you

Related

How can I create dynamic table in Thymeleaf..?

I am new to Thymeleaf and trying to create a dynamic table on Themeleaf template.
How can I do it..??
I have been googling by I didn't got any proper answer. The issue is I cannot iterate List< Map< String,Object >>. I can have any number of columns and columns name could be any thing.
<tr class="headings">
<th class="column-title">ID</th>
<th class="column-title">Name</th>
<th class="column-title">Salary</th>
<th class="column-title">Status</th>
</tr>
</thead>
<tbody>
<tr class="even pointer" th:each="row:${rows}" id = "tablerow">
<td class=" " th:text="${row.getId()}">Id</td>
<td class=" " th:text="${row.getName()}">Name</td>
<td class=" " th:utext="${row.getSalary()}">Salary</td>
<td class=" " th:text="${row.getStatus()}">Active</td>
</tr>
</tbody>
I need to set values dynamically since if query of result will keep changing . right now column name are hard coded and value are also getting by row.getId what if there is no Id, it could be anything in rows what shall I use than..? example row.<>.
rows is obtained as List< Map< String, Object>>.
Thanks in advance.
You can iterative over a Map just as easily as you can a List. The simplest form of this would be:
<tbody>
<tr class="even pointer" th:each="row: ${rows}" id="tablerow">
<td th:each="field: ${row}" th:text="${field.value}" />
</tr>
</tbody>
However, since Maps don't have a specific ordering (unless you're using something like a TreeMap), the way I would do it would be something like this (complete example should match your example table):
Controller
List<String> headers = Arrays.asList("ID", "Name", "Salary", "Status");
List<Map<String, Object>> rows = new ArrayList<>();
rows.add(Map.of("ID", "1", "Name", "Jim", "Salary", "50000", "Status", "active"));
rows.add(Map.of("ID", "2", "Name", "Sally", "Salary", "50000", "Status", "inactive"));
Template
<table>
<thead>
<tr class="headings">
<th th:each="header: ${headers}" class="column-title" th:text="${header}" />
</tr>
</thead>
<tbody>
<tr class="even pointer" th:each="row: ${rows}" id="tablerow">
<td th:each="header: ${headers}" th:text="${row.get(header)}" />
</tr>
</tbody>
</table>
Which will produce:
<table>
<thead>
<tr class="headings">
<th class="column-title" >ID</th>
<th class="column-title" >Name</th>
<th class="column-title" >Salary</th>
<th class="column-title" >Status</th>
</tr>
</thead>
<tbody>
<tr class="even pointer" id="tablerow">
<td >1</td>
<td >Jim</td>
<td >50000</td>
<td >active</td>
</tr>
<tr class="even pointer" id="tablerow">
<td >2</td>
<td >Sally</td>
<td >50000</td>
<td >inactive</td>
</tr>
</tbody>
</table>

problems with xpath evaluation

If I want to extract hrefs only under Type1, basically, 1,2,3,4. htm but not including 5.htm, how to do that?
What I have for now is ://table[#class='leftnav']//a"
Thanks !
<table width="240" border="0" cellpadding="0" cellspacing="0" class="leftnav">
<tr class="leftnav">
<th>Type1</th>
</tr>
<tr class="leftnav">
<td>2013</td>
</tr>
<tr class="leftnav">
<td>2012</td>
</tr>
<tr class="leftnav">
<td>2011</td>
</tr>
<tr class="leftnav">
<td>2010</td>
</tr>
<tr class="leftnav">
<th>Type2</th>
</tr>
<tr class="leftnav">
<td>2013</td>
</tr>
</table>
Try this xpath:
//tr[(preceding-sibling::tr/th)[last()]="Type1"]/td/a

Trying to find XPath for multiple TDs

I want to extract the Address for specific Numbers (the first TD) of this table. The only unique identifier for the table is the H3.
Here is the code for the table:
<table width="95%" cellpadding=5 cellspacing=0 border=1>
<tr><td colspan="4"><h3>The list</td></tr>
<tr>
<td>Number</td><td>First Name</td>
<td>Last Name</td><td>Address</td>
</tr>
I have tried:
//table[#h3=’See this now’]/’tr/td[87] and td[107] and td[116]
I am new to xpath, and programming in general. It's pretty fun, but would love to be able to figure this one out!! Appreciate any help :D
First, your HTML is wrong.
You did not close your Table element.
You did not close your H3 element.
You must enclose your attributes in quotes.
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h3>The list</h3>
</td>
</tr>
<tr>
<td>Number</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
Once you have fixed the formatting of your XHTML. You can traverse the document tree.
XPATH
Any table, with any td that has a h3.
//table//td/h3
Will return
<h3>The list</h3>
For the number
//table//tr[2]/td[1] <-- any table, the second tr element in this table, the first td in that second tr
Will return
<td>Number</td>
So if we add multiple tables to a document and you want to find multiple results for each element in any table, this is quite simple. Say we have a XHTML document with many tables inside a parent element, for example 'root' element.
<root>
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h3>The list</h3>
</td>
</tr>
<tr>
<td>123</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h3>The list</h3>
</td>
</tr>
<tr>
<td>456</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h3>The list</h3>
</td>
</tr>
<tr>
<td>789</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
</root>
We can extract the number of the first table data in each second row in every table using the following XPATH expression:
//table/tr[2]/td[1]
This will give us the result of
<td>123</td>
-----------------------
<td>456</td>
-----------------------
<td>789</td>
Now, say we have several tables, but only one table is very important to us, the table must have a H3 element, no other element is important to us, and if this table has a H3 element, we want to extract the second rows first td.
<root>
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h4>Ignore me!</h4>
</td>
</tr>
<tr>
<td>1164961564896</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h1>I'm not interesting</h1>
</td>
</tr>
<tr>
<td>456456466465</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
<table width="95%" cellpadding="5" cellspacing="0" border="1">
<tr>
<td colspan="4">
<h3>IM THE IMPORTANT TABLE!</h3>
</td>
</tr>
<tr>
<td>123456789</td>
<td>First Name</td>
<td>Last Name</td>
<td>Address</td>
</tr>
</table>
</root>
We can acomplish this by traversing back up the tree if we are successful in finding the H3 element, then go to the next tr.
//table//h3/../../../tr/td[1]
Will return
<td colspan="4">
<h3>IM THE IMPORTANT TABLE!</h3>
</td>
-----------------------
<td>123456789</td>

Escaping characters with ajax and ColdFusion

Hello I've got an issue with an encode failing. Can anyone spot where I'm going wrong?
<form>
<table cellspacing="0" cellpadding="0" border="0" style="background-color:#ededed;padding:50px;">
<tr>
<td align="left"><b>Screen? (eg. Index)</b></td>
</tr>
<tr>
<td align="left"><input type="text" name="strFeedbackScreen" value="" style="width:300px;"></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<tr>
<td align="left"><b>Comments:</b></td>
</tr>
<tr>
<td align="left"><textarea name="strFeedbackComments" style="width:400px;height:150px;"></textarea></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<tr>
<td align="left"><b>Thank you for your feedback.</b></td>
</tr>
<tr>
<td style="height:10px"></td>
</tr>
<cfoutput>
<tr>
<td align="left"><input type="button" value="Send" class="button"
onMouseover="this.className = 'buttonover';"
onMousedown="this.className = 'buttonover';"
onMouseOut="this.className = 'button';"
onclick="sendfeedback('strFeedbackScreen='+escape(this.form.strFeedbackScreen.value)+',strFeedbackComments='+escape(this.form.strFeedbackComments.value),'send_feedback_action_ajax')">
</td>
</tr>
</cfoutput>
</table>
</form>
is the form
<cfoutput>
<cfmail to="feedback#example.com" from="feedback#example.com" subject="Feedback left" type="html">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>**** This email has been sent to all concerned ****</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<cfif application.ds eq "App1">
<tr>
<td>This feedback has been left on App 1.</td>
</tr>
<cfelseif application.ds eq "App2">
<tr>
<td>This feedback has been left on App 2.</td>
</tr>
<cfelseif application.ds eq "App3">
<tr>
<td>This feedback has been left on App 3.</td>
</tr>
</cfif>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>From:</b></td>
</tr>
<tr>
<td>#session.stafffirstname# #session.staffsurname# - #session.staffemail#</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>Screen:</b></td>
</tr>
<tr>
<td>#strFeedbackScreen#</td>
</tr>
<tr>
<td style="height:10px;"> </td>
</tr>
<tr>
<td><b>Comments:</b></td>
</tr>
<tr>
<td>#strFeedbackComments#</td>
</tr>
</table>
</cfmail>
</cfoutput>
is the action.cfm
and the javascript is
function sendfeedback(fields,action) {
turnLayeron('ajaxloading');
nocache = Math.random();
http.open('get', '/ajax.cfm?action='+action+'&fields='+fields+'&nocache='+nocache);
http.onreadystatechange = function() {
if(http.readyState == 4){
closepopout();
turnLayeroff('ajaxloading');
}
};
http.send(null);
}
I've been trying to get uriencode working, but it encodes my string before it gets emailed.
Change your JavaScript to following:
function sendfeedback(fields,action) {
http.open("POST", '/ajax.cfm?action='+action+'&nocache='+nocache, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function() {
if(http.readyState == 4){
closepopout();
turnLayeroff('ajaxloading');
}
};
http.send(fields);
}
Also change your function call to:
onclick="sendfeedback('strFeedbackScreen='+escape(this.form.strFeedbackScreen.value)+'&strFeedbackComments='+escape(this.form.strFeedbackComments.value),'send_feedback_action_ajax')"

Tablesorter not sorting millions

I'm building a mobile real estate website for my wife's business using Tablesorter to sort by price. It works fine for 6 digit numbers (including $s and commas), e.g. $600,000. However it fails when confronting a 7 digit number, e.g. $1,295,000.
In my
<script type="text/javascript" id="js">$(document).ready(function() {
$("table").tablesorter({
// sort on the second column, order asc
sortList: [[1,0]],
headers: {
1: { sorter: 'digit' } // column number, type
}
});
});
<table cellspacing="2" class="tablesorter { 0: { sorter: false}, 1: {sorter: true} }">
<thead>
<tr>
<th width="158" class="headerempty">Property</th>
<th width="130" class="{'sorter':'currency'}">Sort by Price</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><img src="../sales/29 Laurel Way/prepped_images/29lw-for_mobile.jpg" title="Tap for Details" alt="29 Laurel Way" width="150" height="100" border="0"></td>
<td class="{'sorter':'currency'}">$329,000</td>
</tr>
<tr class="odd">
<td><img src="../sales/Aetna Lane/al_for_Mobile.jpg" width="150" height="100"></td>
<td class="{'sorter':'currency'}">$175,000</td>
</tr>
<tr class="odd">
<td><img src="../sales/Atop Smith Hill/prepped/ash_mobile.jpg" width="150" height="100"></td>
<td class="{'sorter':'currency'}">$1,295,000</td>
</tr>
<tr class="odd">
<td><img src="../sales/Beech Hill/bh_mobile.jpg" width="150" height="100"></td>
<td class="{'sorter':'currency'}">$595,000</td>
</tr>
<tr class="odd">
<td class="{'sorter':'currency'}"><img src="../sales/Bluefield/b_mobile.jpg" width="150" height="100"></td>
<td>$299,000</td>
</tr>
</tbody>
</table>
Any thoughts on solving this one? Many thanks in advance, clpix
Constructions like td class="{'sorter':'currency'}" make me scary. You probaly should define table with class sortable and init table sorted in JS using this class, and define sorting parameters in constructor:
$(".sortable").tablesorter({
// sort on the second column, order asc
sortList: [[1,0]],
headers: {
1: { sorter: 'currency' } // column number, type
}
});
<table class='sortable'>
<tr>
<td>$1.000.000</td>
</tr>
......
</table>
And check out delimeter . or ,
This code work fine.

Resources