Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:59:06+00:00 2026-05-26T02:59:06+00:00

I randomly get a row from a mysql-database using php (ugly random, I know).

  • 0

I randomly get a row from a mysql-database using php (ugly random, I know). I then want to update a specific field in the row that I get (using form or POST), but I can’t seem to get it to work. I have tried to create an alias for the specific ID to use in the form-post, but that failed.

$query_Recordset1 = "SELECT id, username, message, ttime, field1, field2 FROM table WHERE done = 0 ORDER BY RAND() LIMIT 1";

Then I want to update field1 if a specific submit-button is pressed, the important thing is that it writes to the random row (specific ID) that is fetched.

<?php      
 if($submit)
 {     mysql_select_db("database", $connection);
       $sql = "UPDATE table SET field1 = field1 +1 WHERE id = '???')";
       $result = mysql_query($sql);
 }
?>
<form method="post" action="">
<input type="submit" name="submit" value="submit">
</form>

Any takes on my problem? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:59:07+00:00Added an answer on May 26, 2026 at 2:59 am

    You are doing it right

    $query_Recordset1 = "SELECT id, username, message, ttime, field1, field2 FROM table WHERE done = 0 ORDER BY RAND() LIMIT 1";
    $query = mysql_query($query_Recordset1);
    $result = mysql_result($query);
    while($result = mysql_fetch_object($result)){
        $sql = "UPDATE table SET field1 = field1 +1 WHERE id = '".mysql_real_escape_string($result->id)."')";
        $new = mysql_query($sql);
    }
    

    That’s just an example.

    In you example, you would probably want to create a hidden field that contains the id

    <input type="hidden" value="<?php echo $result->id; ?>" />
    

    Then on your receiving page

       mysql_select_db("database", $connection);
       $sql = "UPDATE table SET field1 = field1 +1 WHERE id = '".mysql_real_escape_string($_POST['id'])."')";
       $result = mysql_query($sql);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i return a row from my mySQL database, I get a ? instead
I want to get 1000 records from a table randomly, so I use: SELECT
I have an SPListItemCollection. I basically want to get one of the items (randomly)
Starting with an array with 10K values. I want to randomly get 1000 values
I'm trying to get a randomly picked background image (from a selection of 4
I've been making a game using the rokonandroid game engine, but I randomly get
I am using suds 0.3.6. When creating a suds client, I randomly get an
I have a datagridview and a combobox which get populated randomly with data. However,
I will get the error below randomly when I'm running an asp.net application I
Is there a way to get the value of a HashMap randomly in Java?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.