在数据显示后,我希望从MySQL中删除确切的文本,我有一个随机生成器,它从一行中获取数据并随机显示它
架构:“我的世界”,表中有一行名为"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] . " "
?>更新:
更明确地说
这是来自数据库的体系结构

和带有刷新按钮的php页面。

每次用户按下刷新按钮时,他都会从数据库中随机获得一个数据(例如: test1,如果他再次按下test2或test3或TEST4-全部随机数据)。例如,一旦他获得test 1,数据库中的文本1数据将被删除,因此它将不会再次生成,因此在他按下刷新按钮后,他将显示一个数据,同时他将从数据库中删除该数据。
发布于 2014-12-10 22:04:38
由于mysql已被弃用,因此您应该使用mysqli和准备好的语句;
下面是一个如何删除mysql条目的简短示例
$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();但如果只想删除条目的列,则需要使用UPDATE查询
$stmt = $mysqli->prepare("UPDATE table SET column = ? WHERE id = ?");
$stmt->bind_param('si',$new_value, $id);
$stmt->execute();其中$new_value可以是null,也可以是您想要的任何值。
发布于 2014-12-10 22:11:22
如果我没理解错你的问题:
<?php
...
$max = count($rows) - 1;
$r = rand(0, $max);
/// if $rows[$r][0] is ID column
mysql_query("delete from minecraft where id = ".$rows[$r][0];
OR
mysql_query("update minecraft set list='' where id=".$rows[$r][0];
echo $rows[$r][0];
?>发布于 2014-12-11 02:31:07
更新:
更明确地说
这是来自DB http://i.stack.imgur.com/crvh0.png和带有刷新按钮http://i.imgur.com/F1Q3mAx.png的php页面的结构
每次用户按下刷新按钮时,他都会从数据库中随机获得一个数据(例如: test1,如果他再次按下test2或test3或TEST4-全部随机数据)。例如,一旦他获得test 1,数据库中的文本1数据将被删除,因此它将不会再次生成,因此在他按下刷新按钮后,他将显示一个数据,同时他将从数据库中删除该数据。
https://stackoverflow.com/questions/27402492
复制相似问题