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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:52:02+00:00 2026-06-15T00:52:02+00:00

After staring at these lines of code, and researching for hours on multiple coding

  • 0

After staring at these lines of code, and researching for hours on multiple coding forums, I am stuck with the code I have, which does not fully function. I am trying to successfully run this PHP script, so that a text quote can be queried randomly from a MySQL table and displayed in the footer of my website. The quote should change every time a user refreshes the Website. I am also trying to keep a count of how many times each quote is displayed, and then when a particular quote displays on my Website, a counter tell the site user how many times that particular quote has been displayed. My code thus far is:

    <?php

    include('Includes/inc_connect.php');
    $DBName = 'database';
    if (!@mysql_select_db($DBName, $DBConnect))
        echo "<p style='text-align:center'>There are no quotes to view!</p>";
    else {
        $TableName = "randomquote";
        $SQLstring = "SELECT quote FROM $TableName";
                    //executes the query
        $QueryResult = @mysql_query($SQLstring, $DBConnect);
            if ($QueryResult === false)
            {
                echo "<p>Unable to retrieve the data.</p>" . "<p>Error code: " . mysql_errno($DBConnect) . ": " . mysql_error($DBConnect) . "</p>";
            }
            else
            {
                $quote_array = array();//Creates a blank array
    //use a while loop to extract the data from the database table into an indexed array
                while(($Row = mysql_fetch_row($QueryResult)) !== FALSE)
                {
                    $quote_array = $Row[0];
                }
            }

    //assign the contents of the table to an array variable
            $quote_count=count($quote_array);
            $RandomArrayIndex = rand(0, $quote_count-1);
            $quote = stripslashes($quote_array[$RandomArrayIndex]);
                $SQLString = "UPDATE randomquote SET display_count " . " = display_count + 1 WHERE quote = " . $quote_array[$quote];

                $SQLString = "SELECT display_count from randomquote WHERE quote = " . $quote_array[$quote];
                $display_count = @mysql_query($SQLString, $DBConnect);
    //display the random quote on the Web page
                echo "<p style='text-align:center;font-style:italic'><strong>" . $quote . "</strong></p>\n";
                echo "<p style='text-align:center>This quote has displayed " . $display_count . " times.</p>/n";
    }
        else
        {
    //specify that the comments cannot be read
        echo "<p>The quote cannot be displayed at this time</p>\n";
        }
else
{
//specify that there are no quotes
echo "<p>There are no quotes to display.</p>\n";
}

I am a student of both PHP and MySQL, so any and all help and advice is greatly appreciated. Thanks so much!

  • 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-15T00:52:04+00:00Added an answer on June 15, 2026 at 12:52 am

    I believe this may help:

    change

    $SQLstring = "SELECT quote FROM $TableName";
    

    to

    $SQLstring = "SELECT quote FROM $TableName ORDER BY RAND()";
    

    or if you only want one quote at a time

    $SQLstring = "SELECT quote FROM $TableName ORDER BY RAND() LIMIT 1";
    

    I am assuming here that your updating of the display count is working ok.

    You could then drop the random array part of your code.

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

Sidebar

Related Questions

I have these line of code and I want to disable the button after
I have a string which contains binary digits. How to separate string after each
All began with these simple lines of code: string s = 16.9; double d
I am trying to achieve some thing one these lines ,I have two listboxes
I have some code which draws a line along the x, y and z
I have a Plain text file with possibly millions of lines which needs custom
I have odd problem: After starting server I got this error: undefined local variable
Do u have any ideas how to count all characters in string $chars after
I am a newbie learning C# after C++. VS2010. Trying to debug my code,
EDIT After staring at this for 2 days, I do see one issue. 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.