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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:37:42+00:00 2026-05-16T08:37:42+00:00

I have a website that grabs a random entry from a database and displays

  • 0

I have a website that grabs a random entry from a database and displays it for the viewer. This is the code I am currently using:

$rows = "SELECT * FROM xxx";
$rows1 = mysql_query($rows);
$rows2 = mysql_numrows($rows1);
$id= rand(1, $rows2);

This generates an ID number which is used to select a corresponding database entry, and of course there is more php that displays the entry.

In order for the user to generate a new entry from the database, they click a button which refreshes the page using this code:

<form>
<input type=button value="Show me another one" onClick="window.location.reload()">
</form>

This works fine but it’s causing a problem with Google Adsense; it causes Adsense to record huge numbers of page impressions from a given individual user. I haven’t had any correspondence with Google about it, but it must look like I am gaming the system for advertisers who pay “per impression”. I am worried that this is resulting in Google automatically preventing me from receiving revenue from “per impression” advertisements, and may result in my Adsense account being revoked.

So my question is how can make a button that will pull a different entry from the database without refreshing the page? Essentially, I need to find a way to change the “$id” variable after a user clicks the button.

  • 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-05-16T08:37:42+00:00Added an answer on May 16, 2026 at 8:37 am

    You have a couple ways to achieve what you’re trying to do.

    If you want to keep it down to earth HTML and PHP, you can solve your problem by having an IFRAME in your page, with your reload button inside. Of course, you would then not insert the google tracker in the page opened by the IFRAME. You can conceal the IFRAME poor default styling with a little bit of CSS, so it doesn’t stand out your existing page.

    That is far from being the best way to handle this however.

    You should, as suggested by deceze, resort to Ajax to fetch dynamically new information through Javascript. In order to handle this as painlessly as possible, I suggest you choose a Javascript framework to leave all the annoying cross browser bits to it.

    For instance, with jQuery you can do the following (HTML + javascript)

    <!-- new content will appear in the div down below -->
    <div id="content-target">
    </div>
    
    <form>
      <input type="button" id="refresher" />
    </form>
    
    <script type="text/javascript">
      $('#refresher').click(function(){
        $('#content-target').load('generator.php');
        return false;
      });
    </script>
    

    You should spend some time learning a JS framework. It’s a very good investment.

    For jQuery: http://jquery.com/

    Prototype: http://www.prototypejs.org/

    MooTools: http://mootools.net/

    Dojo: http://www.dojotoolkit.org/ (overkill for this kind of script)

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

Sidebar

Related Questions

I have a php script that grabs links from another website. I am storing
I have a script that grabs data from a MySQL database table and creates
I have a bit of ajax that grabs some content from my website and
I have a simple website that grabs html using ajax and place it in
I have a website that logs in using an STS, then gets a delegated
I'm creating an events website using PHP. I have a database with an events
Hi I have a website's home page that I am reading in using Curl
I have a string that I have parsed from XML using Google's GDataXML parser,
I am currently using the following code on a website to allow some div's
I have an html string that I get from the response of a website.

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.