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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:10:54+00:00 2026-06-03T10:10:54+00:00

I generated a random monster team from a table, and limited by 6. Now,

  • 0

I generated a random monster team from a table, and limited by 6. Now, I also want to insert the team into user_team which contains the fields
m1,m2,m3,m4,m5,m6

Those represent Monster 1 to Monster 6. Now when I try to insert the generated monsters into the team, only the last Monster seems to be inserting into it while I all of my monsters to be inserted.
http://prntscr.com/8zrj2

$sql = "SELECT * from monsterdata ORDER BY RAND() LIMIT 6"; 
$result = mysql_query($sql);
// this checks if you have a result
if ($result == null) echo "No result";
else {  
    while (($row = mysql_fetch_array($result)) != false) {
$row = mysql_fetch_array($result);
{
// html code here
}
}

the Insert statement is
$monster = $row['id'];
$sql = "INSERT into user_team(m1,m2,m3,m4,m5,m6) VALUES('$monster','$monster','$monster','$monster','$monster','$monster')";
$result = mysql_query($sql);

Just don’t know where/how to place it so it inserts the right values into the right columns.

  • 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-06-03T10:10:56+00:00Added an answer on June 3, 2026 at 10:10 am

    If it were me, I would push the ids into an array and then use that like so:

    $monsterIds = array();
    while(($row = mysql_fetch_array($result)) !== false) {
        $monsterIds[] = $row['id'];
    }
    mysql_query("INSERT INTO user_team (m1, m2, m3, m4, m5, m6) VALUES ('{$monsterIds[0]}', '{$monsterIds[2]}', '{$monsterIds[3]}', '{$monsterIds[4]}', '{$monsterIds[5]}')") or die(mysql_error());
    

    Also, don’t forget to use the triple equals when comparing row results so that you don’t get caught by a weird bug where things evaluate to false that aren’t actually false (=== is the way to go with many functions which might return either an array, integer, or a boolean depending on the outcome).

    The values will be placed in the columns in the order they are supplied.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After providing the same program which reads a random generated input file and echoes
I want to generate random colours which can be attractive in pie charts.I have
I want to generate random numbers from -n to n excluding 0. Can someone
i want a program that can add the generated random numbers(unique not repeating) to
I have generated a secure random number, and put its value into a byte.
I want to get some random text generated. I tried writing a basic Java
i want to calculate the missing sprites. for example:- random generated sprites is displaying
I'm having touble in making my random generated image (which is read as a
I need populate with dummy values a table. I need create a random generated
Possible Duplicate: class System.Random .. why not static? Following on from Generated random numbers

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.