PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?
// start a session - note this must be done before any headers are sent.
session_start();
// default number of results
$default_results = 20;
// Increment
$increment = 30;
// check if the session variable $_SESSION['num_results'] isset
if(!$_SESSION['num_results']) {
// if its not then set it as the $default_results
session_register('num_results');
$_SESSION['num_results']=$default_results;
}
// Check if show more has been pressed
if($_POST['showMore']) {
// Add 30 to the $_SESSION['num_results'];
$_SESSION['num_results']+=$increment;
}
// Check if show default has been pressed
if($_POST['showDefault']) {
// reset to default value
$_SESSION['num_results']=$default_results;
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//Connect statements
// Create $kk from Session.
$kk = $_SESSION['num_results'];
$query = "SELECT * FROM comments_table LIMIT $kk";
//Execute query and show table with $kk rows.
?>
<form name="form1" method="post" action="<?php print $_SERVER['PHP_SELF']; ?>">
<input type="submit" name="showMore" value="Show 30 More" />
<input type="submit" name="showDefault" value="Show Default" />
</form>
</body>
</html>
This makes use of PHP sessions to store the number of rows as $_SESSION['num_results'];