显示表中的记录?

时间:2015-07-31 14:56:17

标签: php mysql mysqli

绘制,传输和删除已写入记录的代码。 但我不知道如何处理显示的记录。

基本理念是:

    $mysqli->query("SET @ROW_ID := (SELECT id FROM klucz ORDER BY RAND() LIMIT 1);");
    echo  $mysqli['game'].  $mysqli['steam'].  ;

以下是整个代码:

        {

        $mysqli = new mysqli("localhost", "root", "", "klucze");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}



/* set autocommit to off */
$mysqli->autocommit(FALSE);

/* Insert some values */
$mysqli->query("SET @ROW_ID := (SELECT id FROM klucz ORDER BY RAND() LIMIT 1);");

    echo  $mysqli['game'].  $mysqli['steam']. "Wylosowana gra to: <BR>Twoj kod do gry:" ;



$mysqli->query("INSERT INTO kluczuzyty SELECT * FROM klucz WHERE id = @ROW_ID;");



/* commit transaction */
$mysqli->commit();

/* drop table */
$mysqli->query("  DELETE FROM klucz WHERE id = @ROW_ID;");







/* close connection */
$mysqli->close();
}

1 个答案:

答案 0 :(得分:0)

对此进行了尝试,但它仍然没有多大意义。 编辑我想我明白你现在正在尝试做什么。看一看。

<?php
$mysqli = new mysqli("localhost", "root", "", "klucze");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* set autocommit to off */
$mysqli->autocommit(FALSE);

if($results = $mysqli->query("SELECT id FROM klucz WHERE ORDER BY RAND() LIMIT 1")){
    while($row = $results->fetch_Assoc()){
        $ROW_ID = $row['id'];
    }
    // Edited after comment
    $results->free();
}
if(isset($ROW_ID)){
    if($results = $mysqli->query("SELECT * FROM klucz WHERE id = $ROW_ID");
        while($row = $results->fetch_assoc()){
            echo  "{$row['game']}{$row['steam']}Wylosowana gra to: <BR>Twoj kod do gry:";
        }
        $results->free();
    }
    $mysqli->query("INSERT INTO kluczuzyty SELECT * FROM klucz WHERE id = $ROW_ID;");
    $mysqli->query("DELETE FROM klucz WHERE id = $ROW_ID;");
}
$mysqli->close();

?>