繁体   English   中英

如何将索引重置为0

[英]How can I reset index to 0

我应该做一个“支票”,应该有(Index,id,....),但是索引应该在100之后重设,但是id必须是auto_incremented。 这是我的代码。 我没有得到如何将索引重置为0的方法。我什至无法显示indexs的值,每次添加东西时它都显示为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

看看您的phpmyadmin页面中是否有auto_increment选项,您只需要对id字段进行两个字段检查自动递增,对于索引,您只需获取它并将其保存到名称为number_index的另一个字段中(因为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>";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM