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

Page doesn't expand for content
Hi. I've been testing a query I made. It's here http://lapr1.6te.net/inquerito.php
The page doesn

Multiple arrays inside data
Hi,

Simple question. I have a column called "array" in my database, and inserted in

Something like an INI editor or a DelimitedText-Editor
Hi all,

Am very, very, very new to PHP and not sure if I should be posting this to a Javascri

Passing vars to the DB
I have 3 small testing tables:

ID TYPE
1 pepperoni
2 C. bacon
3 taco

ID TY

Count of reciepients in php mailer
How can i sent a mail to large no of reciepients say 10,00,00 Using PHP MAILER

Shuffle Array
Hi,

I am writing a script for a game that needs players to randomly be assigned a target (ano

want to add a break after a certain amount of characters
i was wondering how to add a break in a blog post after a certain amount of characters... any idea o

Open browser page depending on XML results
Hello,

I have some PHP code that sends webbased from data to an external url ( in the form of

What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin

[newb] Image hosting help.
Hey there, I'm new to php, I know some basics and i can code PWN, I'm only 14 but I'm interested in

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