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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:59:55+00:00 2026-06-12T08:59:55+00:00

I have a MySQL database with 6 columns in a table. There will eventually

  • 0

I have a MySQL database with 6 columns in a table. There will eventually be about 100 rows, for now I have 3.

Column titles: FirstName, SecondName, Sentence1, Sentence2, Sentence3, Sentence4

All tables are set to VARCHAR

I want to use php on a web page to call random data from each row, eg mix and match row1 FirstName with row3 SecondName and row2 Sentence1 etc.

I read it is quicker to randomise using php but I really can’t grasp how to do this despite searching.

I can connect to my MySQL database and get results returned using this code:

    <?php
    // Connect to database server
    mysql_connect("localhost", "xxx", "yyy") or die (mysql_error ());
    // Select database
    mysql_select_db("zzz") or die(mysql_error());
    // SQL query
    $strSQL = "SELECT * FROM Users";
    // Execute the query (the recordset $rs contains the result)
    $rs = mysql_query($strSQL);
    // Loop the recordset $rs
    // Each row will be made into an array ($row) using mysql_fetch_array
    while($row = mysql_fetch_array($rs)) {
    // Write the value of the column FirstName (which is now in the array $row)
    echo $row['FirstName'] . "<br />";
      }
    // Close the database connection
    mysql_close();
    ?>

but this just returns one column of data. I need the random code to be returned in the webpage using something like:

echo $firstname . $lastname . $sentence1 . $sentence2 . $sentence3 . $sentence4;

Note, this will be repeated for another 3 or 4 rows afterwards too

echo $firstname_2 . $lastname_2 . $sentence1_2 . $sentence2_2 . $sentence3_2 . $sentence4_2;

I’m not too hot on arrays but if someone can get me started it would be great, thanks.

  • 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-12T08:59:57+00:00Added an answer on June 12, 2026 at 8:59 am

    All those telling you to use rand in the SQL query have not read the question. To those people: the asker wants a random combination of data from the rows, not a random row.

    Something like this. It will take all the results from the database and echo a totally random combination. I couldn’t avoid using arrays as they are super useful.

    <?php
    // Connect to database server
    mysql_connect("localhost", "xxx", "yyy") or die (mysql_error ());
    // Select database
    mysql_select_db("zzz") or die(mysql_error());
    // SQL query
    $strSQL = "SELECT * FROM Users";
    // Execute the query (the recordset $rs contains the result)
    $rs = mysql_query($strSQL);
    // Array to hold all data
    $rows = array();
    // Loop the recordset $rs
    // Each row will be made into an array ($row) using mysql_fetch_array
    while($row = mysql_fetch_array($rs)) {
    // add row to array.
    $rows[] = $row;
      }
    // Close the database connection
    mysql_close();
    
    // Max rand number
    $max = count($rows) - 1;
    
    // print out random combination of data.
    echo $rows[rand(0, $max)][0] . " " . $rows[rand(0, $max)][1] . " " . $rows[rand(0, $max)][2] . " " . $rows[rand(0, $max)][3] . " " . $rows[rand(0, $max)][4] . " " . $rows[rand(0, $max)][5];
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three mysql table from same database Db1. Three tables have following columns.
I am using Mysql database. I have 3 table-: table Column tier_price customer_id,sku(Unique),price,website catalog_product
i have a large mysql database table in which one column contains values ranging
If I have about 250 entries with 6 columns in a MySQL database, and
I have a mySQL database with a FirstName and LastName column and presently i
Okay, so let's say I have a mysql database table with two columns, one
I have a MySQL database table with two columns that interest me. Individually they
I have a MySQL table in which there are two columns , for text
I have a MySQL database with 3 columns: id | articletitle | articleorganization And
I have several columns in a MySQL database that I would like to add

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.