Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

php - how can I use an alternative of this code? Im trying to give a different number from my database to each user visiting my page

is there any better way than this? sure it is but i dont know how. Im trying to distribute some numbers from my database to each user(host) visiting my page. one number (item) per visit. all i came up with is some primitive way. im asking if there is any faster or shorter way than this? keep in mind that i dont want to use cockies or register the user. the numbers are saved as a string in a column only.

<?php
  include_once 'includes/conn.php';
?>

<!DOCTYPE html>
<html>
    <head>
    <meta charset="UTF-8">

        <title>VeniVidiVici</title>
    </head>
    <body>
<?php

    $query = "SELECT numero FROM potluck LIMIT 1;"; 
    $result = mysqli_query($conn, $query); 
    $resultCheck = mysqli_num_rows($result);
    echo $resultCheck ."<br>";
    if ($resultCheck > 0){ 
      $row= mysqli_fetch_row($result);
      echo $row['0'];
      $del = "DELETE FROM potluck LIMIT 1;";
      mysqli_query($conn, $del); 
      
       }        
?>      
        
    </body>
</html>

i dont the users getting the same number and when the database finishes all the rows i want to stop serving the numbers. numbers in the database are unique.

numero
11-12-13
13-14-17
23-45-55

ps: the code works i just need an alternative solution instead of deleting my rows in database and replacing each day with a new table.

question from:https://stackoverflow.com/questions/65916585/how-can-i-use-an-alternative-of-this-code-im-trying-to-give-a-different-number

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...