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!

No comments posted yet

Your Answer:

Login to answer
119 Like 50 Dislike
Previous forums Next forums
Other forums

Email Form Syntax Issue
I need the TO: in email to display To: CEO instead of To: abc@mail.com

How to alter the scri

Problem writing URL into database
How would I write this into the database?

<?php echo "http://".$_SERVER['SER

Help: problem with Headers to download PDF file
Hi,

I'm trying to implement a script where when a user clicks a link he gets a PDF file to op

Certain files upload, while others do not
I want to read the data from an uploaded file. Not sure why, but it only uploads for certain files.

recrawling
Can anyone suggest me how may i know a page is updated before it is being downloaded, so that i can

Running a cron job through PHP/Apache?!
Hello all,
I have a PHP script which makes a cron file from user input. When i try to run the cro

How to implement HTTP connection timeout
Hi All,I would like to implement an HTTP connection timeout.

I am working on a application wh

sendmail code suddenly not working
Hi Guys, I maintain 3 sites (including my own) I use the following code from a french webmaster that

Sort a two dimensional array.
Hi. I've set up a two dimensional array that reads as follows:

Code: $modifiedData = array(

Specific name typed, specific image shown on html page
Hello,

Fairly new to PHP and was curious if someone might know how to solve a fairly simple r

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