display next and previous records in a form
Posted: Fri Jun 15, 2012 2:54 am
I have a simple form to display the records of students.
The 'student.php' page lists all the students and 'details.php' show the details of the selected student from the 'student.php' page in a form.
Now I want to move to NEXT/PREVIOUS record of a student when I click the buttons, without going back to 'student.php' page.
Below is the code for the above said pages......
This is 'student.php'
The code for 'details.php'
Thanks in advance for your help
The 'student.php' page lists all the students and 'details.php' show the details of the selected student from the 'student.php' page in a form.
Now I want to move to NEXT/PREVIOUS record of a student when I click the buttons, without going back to 'student.php' page.
Below is the code for the above said pages......
This is 'student.php'
Code: Select all
<?php
$con = mysql_connect("localhost", "root", "");
$db = mysql_select_db("sample", $con);
$sql = mysql_query("select * from student order by 'id'");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><strong>ID</strong></td>
<td><strong>Name</strong></td>
<td><strong>Class</strong></td>
<td><strong>Marks</strong></td>
</tr>
<?php
while($row = mysql_fetch_array($sql)) {
$id = $row['id'];
$name = $row['name'];
$class = $row['class'];
$mark = $row['mark'];
echo "<tr>
<td>$id</td>
<td><a href='details.php?id=$id'>$name</a></td>
<td>$class</td>
<td>$mark</td>
</tr>";
}
?>
</table>
</body>
</html>
Code: Select all
<?php
$id = $_GET['id'];
$con = mysql_connect("localhost", "root", "");
$db = mysql_select_db("sample", $con);
$sql = mysql_query("select * from student where id='$id'");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
while($row = mysql_fetch_array($sql)) {
// $id = $row['id'];
$name = $row['name'];
$class = $row['class'];
$mark = $row['mark'];
echo "<tr>
<td>Name</td>
<td><input type='text' name='name' value='$name'></td>
</tr>";
echo "<tr>
<td>Class</td>
<td><input type='text' name='class' value='$class'></td>
</tr>";
echo "<tr>
<td>Mark</td>
<td><input type='text' name='mark' value='$mark'></td>
</tr>";
}
?>
<tr>
<td colspan="2"><input type="submit" name="first" value="First" />
<input type="submit" name="previous" value="Previous" />
<input type="submit" name="next" value="Next" />
<input type="submit" name="last" value="Last" /></td>
</tr>
</table>
</form>
</body>
</html>