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 899549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:14:11+00:00 2026-05-15T15:14:11+00:00

$query = SELECT users FROM tabl ORDER BY RAND(); $result = mysql_query ($query) or

  • 0
$query = "SELECT users FROM tabl ORDER BY RAND()";
$result = mysql_query ($query)
    or die ("Query '$query' failed with error message: \"" . mysql_error () . '"');

while ($row = mysql_fetch_array($result)) {
    $users[] = $row[0];
}

$current = end($users);
$partners = array();
foreach ($users as $user)
{
        $partners[$user] = $current;
        $current = $user;
}
print_r($partners);

$query2 = "UPDATE tabl SET partner = {$partners[0]} WHERE users = '$users'";
mysql_query ($query2)
    or die ("<br>Query '$query2' failed with error message: \"" . mysql_error () . '"');

That’s the code I’m working with. Everything is good until query2. I’ve tried every variation I can think of, but nothing works.

The table on has two fields: users and partners. The code pulls the users in random order, then assigns them to eachother in a circle. I need to populate the partners field with the assignments.

  • 1 1 Answer
  • 2 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-15T15:14:12+00:00Added an answer on May 15, 2026 at 3:14 pm

    Place the update query inside the foreach loop, then you have the partner and user variables to hand without diving into the array later on:

    foreach ($users as $user)
    {
            $partners[$user] = $current;
            $current = $user;
            $query2 = "UPDATE tabl SET partner = '{$partners[$user]}' WHERE users = '{$user}'";
            mysql_query ($query2)
              or die ("<br>Query '$query2' failed with error message: \"" . mysql_error ()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function addAds($n) { for ($i=0;$i<=$n;$i++) { while($row=mysql_fetch_array(mysql_query(SELECT * FROM users))) { $aut[]=$row['name']; } $author=$aut[rand(0,mysql_num_rows(mysql_query(SELECT
$result = mysql_query(SELECT * FROM users); $values = array(); while($row = mysql_fetch_array($result)) { $values[]
a simple $stuff = mysql_query(SELECT * FROM users); while($s = mysql_fetch_array($stuff)){ # .... }
$result=mysql_query(SELECT * FROM users WHERE pass='.sha1($_POST['mainloginpass']).'); if(mysql_num_rows($result)==1){ it says that mysql_num_rows() expects parameter 1
I'm trying this: $result = mysql_query( SELECT Users.*, Posts.* FROM Users INNER JOIN Posts
I have the following result from the following query: SELECT users.ID, user_registered, post_date, post_type
My php code: $sql = mysql_query(SELECT * FROM users WHERE user_id IN (1,3)); while($row
I want to do something like this: $query=mysql_query(SELECT userid FROM users WHERE username='$username'); $the_user_id=
I'm using the following query to select users from my 'users' table with the
this is the mysql query SELECT * FROM users AS up JOIN users AS

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.