2017-02-11 76 views
0

我應該做一個「檢查」,應該有(Index,id,....),但索引應該在100之後重置,但是id必須是auto_incremented。 這是我的代碼,我做了什麼。我沒有得到如何重置索引到0.我甚至不能顯示索引值,它顯示0每當我添加的東西。如何將索引重置爲0

<?php 
    $host = "localhost"; 
    $user = "root"; 
    $password = ""; 
    $database = "dbcar"; 

    $number = ""; 
    $state_number = ""; 
    $model = ""; 
    $status = ""; 
    $conditions = ""; 
    $date = ""; 
    $number_index = "1"; 

    $connect = mysqli_connect($host,$user,$password,$database); 

    echo "<h1>Report Log </h1>"; 
    $sqlget = "SELECT * FROM carserv ORDER BY date DESC LIMIT 1"; 
    $sqldata = mysqli_query($connect,$sqlget) or die("error"); 

    echo "<table>"; 
    echo"<tr> 
    <th>INDEX</th> 
    <th>ID</th> 
    <th>State Number</th> 
    <th>Model</th> 
    <th>Status</th> 
    <th>Condition</th> 
    <th>Date</th> 
    </tr>"; 


    while($row = mysqli_fetch_array($sqldata,MYSQLI_ASSOC)){ 
     echo" <tr><td>"; 
     echo $row['number_index']; 
     echo" </td><td>"; 
     echo $row['number']; 
     echo" </td><td>"; 
     echo $row['state_number']; 
     echo" </td><td>"; 
     echo $row['model']; 
     echo" </td><td>"; 
     echo $row['status']; 
     echo" </td><td>"; 
     echo $row['conditions']; 
     echo" </td><td>"; 
     echo $row['date']; 
     echo" </td></tr>"; 
    } 
    echo "</table>"; 

    function getPosts(){ 
     $posts = array(); 
     $posts[0] = $_POST['state_number']; 
     $posts[1] = $_POST['number']; 
     $posts[2] = $_POST['model']; 
     $posts[3] = $_POST['status']; 
     $posts[4] = $_POST['conditions']; 
     $posts[6] = $_POST['number_index']; 
     return $posts; 
    } 
?> 

,這裏是我的輸出:http://imgur.com/GOuCcBU

+0

'SELECT'不更改數據庫,'INSERT /更新'做。很難說你的真實代碼是什麼。 –

+0

另外,'INDEX'是一個MySQL保留字https://dev.mysql.com/doc/refman/5.7/en/keywords.html - 查看你的截圖。 –

+0

我可以告訴你我的整個代碼,如果你想 – deluxion

回答

0

採取看看你的phpmyadmin頁有你需要的只是有兩個現場檢查自動遞增的ID字段和索引你只是把它拿來和保存AUTO_INCREMENT選項它在名爲number_index的另一個字段中分貝(因爲索引是保留字)。

通過做這樣的事情重置您的數據庫,以O爲您counter_update.php

if($_POST['index_reset']) { 
    $index_reset = $_POST[index_reset]; 
    mysql_connect("server", "username", "password") or die(mysql_error()); 
    mysql_select_db("database") or die(mysql_error()); 
    $sql = 'UPDATE counters SET number_index =\'0\' WHERE Page = \'$index_reset\';'; 
    } 

和HTML側像這樣

$page_reset = "<form id='Reset' action='counter_update.php' method='post'> 
<button type='submit' name='index_reset' value='$formPage'>RESET</button> 
</form>"; 
+0

是啊,但我怎麼能添加兩個字段與auto_increment?它說,你只能廣告1 auto_increment,我有auto_increment - 號碼 – deluxion

+0

老兄只是身份證作爲自動增量和number_index應該從後端提供,並將其保存到數據庫並休息當達到hundered –

+0

我該怎麼做?我做了2天,並沒有得到它,對不起,即時通訊啓動PHP,MySQL – deluxion

相關問題