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;
Did you know?Explore Trending and Topic pages for more stories like this.
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

How do I give a developer access to a specific directory and nothing else?
I want to give a develop access to a specific directory and nothing else

I can give them an F

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

Problem with php's rename function
So, i'm having a problem with the php rename function. Basically my script 'delete_user.php' attempt

using a loop help
Hi guys , i need some help. I have this loop :
while ($row = mysql_fetch_assoc($Result)) { ?&

Had a simple form script that suddenly stopped working
It was made about a year ago and had been working fine. Last time it was known to work for sure was

Secure pages Sessions vs. Cookies & session_destroy() help
Im new here and new to PHP, I hope you can help me with some questions.

Im writing my web ap

Problem!
I have another problem, when i run this code i get this error "Parse error: syntax error, unexp

Only add new information from XML to MySQL
What I am doing, is taking a xml file, and adding the values to a database. However, what I want to

pointer 102 question
I read a book
1
2
3
4
5
6
7
8
9
10
11
12
int main() {

Taxonomy? Classification? Categorisation?
Not sure if there is a way around this classification problem
I have a supplier who produces

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