首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将索引重置为0

如何将索引重置为0
EN

Stack Overflow用户
提问于 2017-02-11 20:22:18
回答 1查看 117关注 0票数 0

我应该做一个“支票”,应该有(索引,id,...),但是索引应该在100之后重置,但id必须是auto_incremented。以下是我所做的代码。我不知道如何才能将索引重置为0。我甚至不能显示索引的值,每次我添加一些东西时,它都会显示0。

代码语言:javascript
复制
<?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

EN

回答 1

Stack Overflow用户

发布于 2017-02-11 20:27:23

看看你的phpmyadmin页面,有一个索引选项,你只需要有两个字段,检查id字段的自动递增,对于索引,你只需获取它并将其保存到名为number_index的另一个字段中的数据库中(因为索引是一个保留字)。

通过执行以下命令将db重置为O: is your counter_update.php

代码语言:javascript
复制
   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端类似这样的东西。

代码语言:javascript
复制
 $page_reset = "<form id='Reset' action='counter_update.php' method='post'>
<button type='submit' name='index_reset' value='$formPage'>RESET</button>
</form>";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42175804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档