项目没有插入SQL表android的末尾

时间:2015-08-08 19:43:48

标签: php mysql

我从我的Android应用程序发送数据以添加到在线数据库。但是数据不会存储在表的末尾。它存储在表中的随机位置。我该如何避免这种情况?这是我的PHP代码。

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

$response = array();

$title = $_POST['Title'];
$time = $_POST['Time'];
$posted= $_POST['posted'];




require_once __DIR__ . '/db_connect.php';


$db = new DB_CONNECT();


$result = mysql_query("INSERT INTO mukul(Title, Time, posted) VALUES('$title', '$time', '$posted')");

if ($result) {
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";


    echo json_encode($response);
} else {

    $response["success"] = 0;
    $response["message"] = "Oops! An error occurred.";


    echo json_encode($response);
}

?>  

1 个答案:

答案 0 :(得分:0)

没有&#34;表的结尾&#34;在关系数据库中。数据以最方便数据库的顺序存储(受表中索引的影响)。因此,您所询问的并不是一个错误,而是预期的行为。在获取数据时只需使用ORDER BY子句即可确保所需的顺序。与您可能相信的相反(我必须猜测,因为问题有点模糊),执行ORDER BY并不是一个缓慢的操作,特别是如果您对已排序的列有索引。

如果您需要有关索引的帮助,the MySQL manual has you covered