2017-02-11 78 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

相关问题