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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:02:07+00:00 2026-06-09T09:02:07+00:00

I’ve tried looking for a solution in other questions asked before (as always), but

  • 0

I’ve tried looking for a solution in other questions asked before (as always), but I can’t seem to wrap my head around this.

See, I want to get a number of unique IDs (in random order) from one table and store them in an array without echoing them. Then I want to use that array variable in a loop, so that I can increment the key with every pass, and set another variable to that array variable. Confusing? I think looking at the code will make it more clear.

The problem is I can’t seem to store the values that I’ve queried into an array for later use in the code. I pasted the pertinent part of the code with my spots of trouble indicated by comment /* */ tags.

Any help is appreciated.

<?php

include ('parse_functions.php');

if ($fetch['use_rand']=='yes')

{ $loop = 5;    
$concept = $fetch['concept'];
$countRandom = "SELECT exID FROM examples WHERE concept='$concept' ORDER BY RAND()";
$askForRandom = mysql_query($countRandom) or die(mysql_error());
/* HERE I NEED TO STORE RANDOM KEYS (exID) INTO AN ARRAY */ }

else

{  if (!empty($fetch['ex5'])) { $loop = 5; }
 elseif (!empty($fetch['ex4'])) { $loop = 4; }
 elseif (!empty($fetch['ex3'])) { $loop = 3; }
 elseif (!empty($fetch['ex2'])) { $loop = 2; }
 elseif (!empty($fetch['ex1'])) { $loop = 1; }
 else { $loop = 0; }

    }

     if ($loop!==0)

      {

         echo '<div id="examples">' . "\n";
         echo '<table class="showExample" cellspacing="0" cellpadding="0" border="0" align="center">' . "\n";

         $turns = 1;

             do {

             if ($fetch['use_rand']=='no')

              { $exID = $fetch['ex'.$turns.'']; }

             else

              { $exID = /* THIS IS WHERE I WILL USE "RANDOM VARIABLE" */; }

             $askExamples = "SELECT * FROM examples WHERE exID='$exID'";
             $getExamples = mysql_query($askExamples) or die(mysql_error());
             $sortExamples = mysql_fetch_assoc($getExamples);

             echo '<tr>' . "\n";

// ...and so on
  • 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-09T09:02:09+00:00Added an answer on June 9, 2026 at 9:02 am

    If all you need to do is store the info in an array, here’s an easy way about it.

    /* code 
    to open
    db here
    */
    
    /* assuming you have a value for $concept */
    
    $countRandom = "SELECT exID FROM examples WHERE concept='$concept' ORDER BY RAND()";
    $askForRandom = mysql_query($countRandom) or die(mysql_error());
    
    $Element = 0; //Array elements start at ZERO. So this is to intialise it.
    while ($Fields = mysql_fetch_array($askforRandom)) //As long as there are records, get them.
        {
        //Records are retrieved one at a time. So store each one's exID in the array element
        $Data[$Element] = $Fields["exID"];
        //Soon after storing one, increment the value of the $Element variable so it is ready for the next one.
        $Element++
        }
    
    /* now you have the data in the array. So you can do what you like with it. */
    

    hope it helps

    NOTE: when reading the array, make sure you put the condition to check that your counter is LESS than $Element. This is because after reading the last record, $Element is incremented by one. Hope this is clear.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I know there's a lot of other questions out there that deal with this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I want to construct a data frame in an Rcpp function, but when I

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.