In my Mysql Database I've one Column called notesUpdate
where I inserting many data with date ,username and notes. So that notesUpdate
Column hold following data.
2014-07-23 04:01 AM alex : First Note{ASUSIBBIR}
2014-07-23 04:01 AM alex : Second Note{ASUSIBBIR}
2014-07-23 04:02 AM alex : Third Note{ASUSIBBIR}
2014-07-23 04:02 AM alex : Fourth Note{ASUSIBBIR}
Note: {ASUSIBBIR} is a separator I'm using.
Now I'm trying to fetch these data in Descending Order. I mean Last inserted data should be at First. So I'm using following query. I know it's not right but can't get any idea how can show these data by Descending Order ?
$query = mysql_query("SELECT notesUpdate FROM contact_details WHERE cdid = '$id' ORDER BY
notesUpdate DESC");
Data Show Should Be Look Like This:
2014-07-23 04:02 AM alex : Fourth Note
2014-07-23 04:02 AM alex : Third Note
2014-07-23 04:01 AM alex : Second Note
2014-07-23 04:01 AM alex : First Note
How I inserting Data to DB
$username = $_SESSION['front_username'];
$contetn = $date;
$contetn .= " ";
$contetn .= "$username";
$contetn .= " : ";
$contetn .= mysql_real_escape_string(htmlspecialchars(trim($_POST['contentText'])));
$cdid = $_POST['cdid'];
$contetn .= "{ASUSIBBIR}"; // this is a separator
$query = mysql_query("UPDATE contact_details SET notesUpdate = CONCAT(notesUpdate,
'$contetn') WHERE cdid = '$cdid' LIMIT 1")
Any help ?
Update:
This is the form where I insert data to db:
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h2>Write your Notes</h2></td>
</tr>
<input type="hidden" value="<?php echo $id; ?>" name="cdid" id="cdid"/>
<tr>
<td><textarea name="contentText" id="contentText" cols="53" rows="5"></textarea></td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type="submit" value="Save" name="submit" class="submit" id="addNewNotes"/></td>
</tr>
</table>
This is Jquery part:
$(document).ready(function() {
$('body').on('click', '#addNewNotes', function(e){
e.preventDefault();
var formData = new FormData($(this).parents('form')[0]);
var cid=$(this).parents('form:first').find('#cdid').val();
$("#loading-image").show();
$.ajax({
url: 'response.php',
type: 'POST',
xhr: function() {
var myXhr = $.ajaxSettings.xhr();
return myXhr;
},
success: function(data){
getDetails(cid);
$("#loading-image").hide(); //hide loading
$("#Notesboxsuccess").html(data).show();
},
// complete: function(){
// $("#loading-image").hide(); //hide loading here
//},
data: formData,
cache: false,
contentType: false,
processData: false
});
});
});