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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:18:50+00:00 2026-06-12T03:18:50+00:00

I have a MySQL database and I need a PHP to pull a random

  • 0

I have a MySQL database and I need a PHP to pull a random row. I have successfully created

$query = "SELECT * FROM $usertable
          WHERE region='UK'          
          ORDER BY RAND() LIMIT 1";

This successfully randomly pulls a row; however, it is not limited to where region=2.

I need to be able to:

  1. pull randomly when region=UK
  2. pull randomly when region=UK or ##

(where ## is actually another region, for example, YK = Yorkshire)

Basically I need it to select rows randomly but ONLY when region=UK.

region is a label for one of my fields/collumns, and UK is the content of the VARCHAR in that for a number of rows.

I have the rest of the code sorted.

I have a simple database and the php as follows:

<?php
//Sample Database Connection Syntax for PHP and MySQL.
//Connect To Database
$hostname="carbonmarketing.db.9606426.hostedresource.com";
$username="MarketReadOnly";
$password="Read0nly1";
$dbname="carbonmarketing";
$usertable="ClientList";
$advertfooter = "advertfooter";
mysql_connect($hostname,$username, $password) or die ("<html>%MINIFYHTML4333ddb1f6ba50276851b9f9854a5c817%</html>");
mysql_select_db($dbname);
# Check If Record Exists
$query = "SELECT * FROM $usertable
          WHERE region='UK'          
          ORDER BY RAND() LIMIT 1";
$result = mysql_query($query);
if($result)
{
    while($row = mysql_fetch_array($result))
    {
        $advertfooter = $row["$advertfooter"];
        echo "$advertfooter";

    }
}
?>

But, it’s just pulling randomly for all values of the region column

Let me know if it would help for you to see the database.

  • 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-12T03:18:52+00:00Added an answer on June 12, 2026 at 3:18 am
    $query = "SELECT * FROM $usertable
              WHERE region IN ('UK','YK')          
              ORDER BY RAND() LIMIT 1";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here my code, I need to insert into mysql database I have mysql,php,android 1)
I need to grab the result of a query, with php from a mysql
I'm trying to pull out information from a database with PHP and have the
I have MySQL database server I need to update and retrieve data to/from MySQL
I already have the mysql database made, I just need to connect php to
I need to use PHP to copy data from one MySQL database to another.
I need to create a menu with PHP from a MySQL database. Table called
I'm trying to pull data from my database using json in php. I have
I have a MySQL database, and a particular table in that database will need
I have table which contains double values stored in mysql database ...I need to

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.