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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:52:36+00:00 2026-06-05T15:52:36+00:00

I wrote a PHP script that retrieves values from a MySQL Query. I used

  • 0

I wrote a PHP script that retrieves values from a MySQL Query. I used mysql_fetch_array to add the results to an array. I am trying to select a random value from the array, however array_rand doesn’t seem to work. My code is below:

<?php 
session_start();
ob_start();
require_once 'includes/db_connection.php';
require_once 'includes/contest.php';
require_once 'includes/survey.php';
require_once 'includes/poll.php';
require_once 'includes/clients.php';
require_once 'includes/user.php';
//Select All Entries from Contest and Save as Array
//Select 
mysql_connect(localhost,s2ktest_s2kuser, Bc33iyZYQWgUmguBehPI);
$dbname = 's2ktest_s2k';
mysql_select_db($dbname);
$contestid = 20;
$query = "SELECT UserID FROM Contest_Entered WHERE ContestID = $contestid";
//Save Result
$result = mysql_query($query) or die(mysql_error());
//Save All Contest Entries in Array
$entries = mysql_fetch_array($result) or die(mysql_error());

//Output all Rows
//While Each Entry in the Array is a Value
while($entries = mysql_fetch_array($result))
{
echo $entries;
echo "</br>";
}
echo array_rand($entries);
//mysql_free_result($result);
?>
  • 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-05T15:52:38+00:00Added an answer on June 5, 2026 at 3:52 pm

    Maybe because you don’t have any array…
    The while is only generating one row at the time.

    while($entries = mysql_fetch_array($result))
     {
      echo $entries;
      $arr[] = $entries;
      echo "</br>";
     }
     echo array_rand($arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that I wrote in PHP which scrapes data from a
i wrote a php script to generate random values between 1 and 99999999999999999999 (that's
I wrote a php script that must be run on the php interpreter (Without
I'm using Dynatree for the first time and wrote a PHP script that returns
I wrote a PHP-CLI script that mixes two audio (.WAV PCM) files (with some
I am trying to write a PHP script that can upload multiple files. for($i=0;$i<count($_FILES['uploadimg']['name']);$i++){
I am trying to write a PHP script that uses the pdftk app to
I am trying to write a PHP script that listens for incoming $_REQUEST or
I am trying to write a bash or PHP script that will execute a
Alright, so here's my problem. I'm trying to write a script in PHP that

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.