I recently developed a website that showcases random entries from a database to viewers. Here is the current code snippet I am using:
$records = "SELECT * FROM xxx";
$records_query = mysql_query($records);
$num_records = mysql_num_rows($records_query);
$id= rand(1, $num_records);
This code helps in generating an ID number that corresponds to a database entry, followed by additional PHP to display the content.
To allow users to fetch a different entry from the database, they simply click a button that refreshes the page with this piece of code:
<form>
<input type=button value="Show me another one" onClick="window.location.reload()">
</form>
However, this method has been problematic for Google Adsense as it causes multiple page impressions from individual users. Although I haven't received any feedback from Google regarding this issue, it could seem like an attempt to manipulate the system for advertisers paying based on impressions. This concern might lead Google to block revenue from impression-based ads or potentially revoke my Adsense account.
Therefore, my primary question here is: How can I implement a button that retrieves a new database entry without having to reload the page? Ultimately, I aim to modify the "$id" variable after a user clicks the button.