douyu4535 2014-12-10 13:41
浏览 20

显示后从MYSQL中删除PHP数据

After the data is displayed I want the exact text to get deleted from MySQL I have a random generator that gets data from a row and displays it random

Architecture : "minecraft" and inside the table its a row named "list"

<?php
    // Connect to database server
    mysql_connect("localhost", "bdweb_panel", "password") or die (mysql_error ());
    // Select database
    mysql_select_db("bdweb_panel") or die(mysql_error());
$strSQL = "SELECT * FROM minecraft";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Array to hold all data
$rows = array();
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
    // add row to array.
    $rows[] = $row;
}
// Close the database connection
mysql_close();

// Max rand number
$max = count($rows) - 1;

// print out random combination of data.
echo $rows[rand(0, $max)][0] . " " 
?>

Update :

To be more explicit

This is the architecture from the DB

and the php page with a refresh button

Each time a user is pressing the refresh button he gets a data from the DB (EX : test1, and if he press once again test2 or test3 or test 4 - all random data) all random. Once he gets for example test 1, the text 1 data from the DB deletes so it will not be generated once more again, so after he press the refresh button he will display a data and at the same time he will delete it from the data base.

  • 写回答

3条回答 默认 最新

  • dpafea04148 2014-12-10 14:04
    关注

    Since mysql is deprecated you should use mysqli and prepared statements;

    Heres a short example how to delete a mysql entry

    $mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
    $stmt = $mysqli->prepare("DELETE FROM table WHERE id = ?");
    $stmt->bind_param('i', $id); 
    $stmt->execute();
    

    But if you just want to delete the column of an entry you need to use an UPDATE query

    $stmt = $mysqli->prepare("UPDATE table SET column = ? WHERE id = ?");
    $stmt->bind_param('si',$new_value, $id); 
    $stmt->execute();
    

    where $new_value can be null or whatever you want to.

    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了