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

  • Home
  • SEARCH
  • 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 6724409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:41:12+00:00 2026-05-26T09:41:12+00:00

I get a random row from a mysql-server using php. I then display some

  • 0

I get a random row from a mysql-server using php. I then display some information and would like to let the users give feedback on that specific row. However, I can’t seem to transfer the ID correctly to the update.php. (No updating is happening on the server). Can somebody spot out my error?

Mysql-php getting a (ugly) random row:

$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8"); 
$result = mysql_query("SELECT id, username, message, ttime, field1, field2 FROM field WHERE done = 0 ORDER BY RAND() LIMIT 1");  
$array = mysql_fetch_row($result);      

echo json_encode($array);

Then index.php:

<div id="output">
<div id="username">content</div>
<script id="source" language="javascript" type="text/javascript">
$(function () 
  {   $.ajax({                                      
      url: 'api.php',   
      data: "",           
      dataType: 'json',             
      success: function(data)       
      {
        var id = data[0];           
        var vname = data[1];         
        var message = data[2]; 
    var timestamp = data[3]; 

        $('#output').html(timestamp +message );   
         $('#username').html( vname );

      } 
    });

  }); 
  </script>

  <script>
  $(document).jkey('a',function() {
      $.post("update.php", { id: "id"} )
    });
</script>

Then in the update.php:

<?php require_once('Connections/connection.php'); ?>
<?php 
$id = $_POST['id'];
$sql = "UPDATE field SET field1 = field1 +1 WHERE id = '$id'";
$result = mysql_query($sql);
?>
  • 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-26T09:41:13+00:00Added an answer on May 26, 2026 at 9:41 am

    Put a global _id in a script tag, then :

      $.ajax({                                      
      url: 'api.php',          
      data: "",    
      dataType: 'json',             
      success: function(data)    
      {
        var id = data[0]; 
        _id = id;
        //...
    

    and

    <script>
      $(document).jkey('a',function() {
        $.post("update.php", { "id": _id} ) // <--- Look here
      });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I randomly get a row from a mysql-database using php (ugly random, I know).
I'm looking to get a random row from MySQL without using too much time
Is there is any way to get the select Random Records using query from
I am trying to get a random row in MySQL. Here is my approach:
how I can get a random row from a selection in my linq query?
Trying to get a single random row from a model. I pulled this from
I'm running the following code to get a random entry from a dictionary: SELECT
I was testing out a query to get a random integer in MySQL, and
I expected to get a grid of unique random numbers. Instead each row is
I need to fetch a repeatable random set of rows from a table using

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.