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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:24:35+00:00 2026-06-07T12:24:35+00:00

I am having two tables question_bank(ques_id,question,answer,a,b,c,d) random_question_bank(user_id,q1,q2,…………,q20) I have filled the user_id from users.

  • 0

I am having two tables

  1. question_bank(ques_id,question,answer,a,b,c,d)
  2. random_question_bank(user_id,q1,q2,…………,q20)

I have filled the user_id from users.

Now, i want to fill the q1,q2,…….q20 with ques_id(randomly) for every user_id.

Please, HELP with the code.

$result_user = mysql_query("INSERT INTO random_question_bank(user_id) VALUES('".$_SESSION['user_id']."')");
if($result_user)
    echo('<br />user name inserted<br />');
$result = mysql_query("SELECT * FROM question_bank ORDER BY RAND() LIMIT 20");
$q = array();
$i = 1;
while($row = mysql_fetch_assoc($result))
{
    $sql = "INSERT INTO random_question_bank(q.'$i') 
         VALUES('".$row['ques_id']."')
        WHERE user_id ='".$_SESSION['user_id']."'";
    $result_ques = mysql_query($sql);
    $i++;
    if($result_ques)
         echo('<br />q'.$i.'<br />');
    $i++;
}
  • 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-07T12:24:37+00:00Added an answer on June 7, 2026 at 12:24 pm

    Please try the following code:

    $result_user = mysql_query("INSERT INTO random_question_bank(user_id) VALUES('".$_SESSION['user_id']."')");
    if($result_user)
    echo('<br />user name inserted<br />');
    $result = mysql_query("SELECT * FROM question_bank ORDER BY RAND() LIMIT 20");    
    $i = 1;
    while($row = mysql_fetch_assoc($result))
    {
        $sql = "Update random_question_bank set q.'$i' 
         ='".$row['ques_id']."' WHERE user_id ='".$_SESSION['user_id']."'";
    $result_ques = mysql_query($sql);
    $i++;
    if($result_ques)
         echo('<br />q'.$i.'<br />');
    $i++;
    }
    

    According to my knowledge, you can not use where clause with insert statement. Hope it will work for you.

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

Sidebar

Related Questions

I have two tables Question and Option having one to many relationship. after fetching
I have two tables table1 and table2 each having a column named email along
I have two tables in my database schema that represent an entity having a
So i'm having this problem. I have two tables (Oracle), one is called Destination
I'm having some problems trying to perform a query. I have two tables, one
I have two tables but for the purposes of this question, I will only
Can anybody tell me how to select data from two tables, without having to
Excuse the long question! We have two database tables, e.g. Car and Wheel. They
I have two tables. Both contains question id field. I want to get all
Quick question that requires a long explanation.. Say I have two tables - one

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.