Add 5 to a variable when a button is clicked, and re-run a for loop


Posted on 16th Feb 2014 07:03 pm by admin

So I'm making a feedback sort of section on a website with MySQL and PHP, I've gotten the script to do everything I want except for this. I want the script to only show 5 at a time (which i have accomplished no problem), but I'm also trying to make it so that when the user clicks a button it will show the next 5 records in the database so they can view all records, but only 5 at a time. (I hope this makes sense). So I need the button to add 5 to my $start variable, and then re-run my for loop.


$start = 0;
echo $start . "<br /><br />";
$result2 = mysql_query("SELECT * FROM testtable LIMIT $start,5") or die(mysql_error());
$row2 = mysql_fetch_array($result2);

for($counter = 1; $counter <= 5; $counter += 1)
{

echo $row2['ID'] . "<br />";
echo "&nbsp;&nbsp;Subject:<b><font color='red'>&nbsp;" . $row2['Subject'] . "</font></b>";
echo "<br />Message:&nbsp;<b>" . $row2['Message'] . "</b><br /><br />";
$row2 = mysql_fetch_array($result2);

}

mysql_close($con)
?>


<br />

<form>
<input type="button" value="submit" onclick="<?php $start += 5; ?>" />
</form>

<?php echo $start; ?>

Any help would be greatly appreciated!

119 Like 50 Dislike
Previous php-forum Next php-forum
Other php-forum

Reading Most Recent CSV File in Directory
I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to m

puting for loop in 1 value
hi ,

how do i put this code in 1 value:
Code: <?php
for ($i=1; $i<=5; $i

Uploading/Downloading files stored in MySQL database
Hey all,

This problem just came up in my website and I'm having a hard time figuring out what

Undefined Variable: PHP_SELF, pls help
Hi,

Im a newbie on PHP / MySQL programming and Im running a script to search one field on my

1,000 select boxes with 100 options?!
I have 1 drop down select box with 1,000 options.


In some case, there will be 100+ of the

Connect to database that isn't localhost
I am currently doing a small script for a company that doesn't have mySql support on there hosting.

Help with form post data and arrays
Hi all,

I am new to this forum... It has been awhile since i have worked with arrays, and i a

Not adding to db
Hi, I can't figure out why it won't add the record to the database. It's just a simple form to get

RSS poster script?
I have found a script that posts RSS's for me on a site that I'm building. However I would like to a

Baffled by Undefined Index in Simple Array: Please Help!
Hello. I have a form which posts an array to this script. However, I can't seem to access the values

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash