dsxay48646 2014-07-22 18:11
浏览 24
已采纳

使用一列中的ORDER BY显示来自Mysql数据库的数据

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>&nbsp;</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
        });
});

});
  • 写回答

2条回答 默认 最新

  • drhwb470572 2014-07-22 18:28
    关注

    I suggest select notesUpdate and split it to an array, then reverse it and dispay :) But you should consider use some relative table in databese to store changes history.

    $result =  mysql_query("SELECT notesUpdate FROM contact_details WHERE cdid = '$id'");
    $row = mysql_fetch_assoc($result);
    $notesUpdateArray = explode('{ASUSIBBIR}', $row['notesUpdate']);
    $notesUpdateReversedArray = array_reverse($notesUpdateArray);
    
    
    var_dump($notesUpdateReversedArray);
    

    If you wont it as string just implod it back

    $notesUpdateReversed = implode('{ASUSIBBIR}', $notesUpdateReversedArray);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测