Page 1 of 1

MovePrevious MoveNext using links

Posted: Wed Nov 26, 2008 9:15 am
by hellboy83
Hi guys I'm kinda new to php and i need some help. I've goggled around but with no success.

I have a table "employees":

id | name | email | address | job
1 | agnes | agnes...com | new york | accounting
2 | jose | jose...com | california | manager
3 | robert | robert...com | new jersey | IT
4 | anderson | anderson...com | new york | IT
5 | kelvin | kelvin...com | california | IT

I want to look through this data on my form but using links previous or next.

How can this be done guys?

Code: Select all

<?php
include 'confgTableTest.php';
include 'opendb.php';
 
$sql ="SELECT * FROM $tbl_tableTest";
$result =mysql_query($sql);
$row =mysql_fetch_array($result);
 
...
 
?>
<form method=post>
ID:<input type="text" name="id" value="<?php ?>"><br /><br />
Name:<input type="text" name="name" value="<?php ?>"><br /><br />
Address:<input type="text" name="address" value="<?php ?>"><br /><br />
Job:<input type="text" name="job" value="<?php ?>"><br /><br />
City:<input type="text" name="city" value="<?php ?>"><br /><br />
<a href="nextPrevious.php?ID=<?php ?>">Previous</a> 
<a href="nextPrevious.php?ID=<?php ?>">Next</a> 
</form>
[/size]

Re: MovePrevious MoveNext using links

Posted: Wed Nov 26, 2008 9:43 am
by aceconcepts
Search Google for "php pagination"

Re: MovePrevious MoveNext using links

Posted: Thu Nov 27, 2008 1:37 am
by hellboy83
Hi guys i got this code and it's working pretty well. But instead i want this to work with my Mysql table "members" instead of the hard coded arrays. It actually has the same fields ID| Name| Email| Address| Job| City

What changes should be done on the code below to meet those needs?

Code: Select all

<?php
 
$row[0]['ID']="1";
$row[0]['Name']="Agnes";
$row[0]['Email']="Agnes.com";
$row[0]['Address']="New York";
$row[0]['Job']="Accounting";
$row[0]['City']="New York";
 
$row[1]['ID']="2";
$row[1]['Name']="Jose";
$row[1]['Email']="Jose.com";
$row[1]['Address']="Cali";
$row[1]['Job']="Manager";
$row[1]['City']="Cali";
 
$row[2]['ID']="3";
$row[2]['Name']="Robert";
$row[2]['Email']="Robert.com";
$row[2]['Address']="New Jersey";
$row[2]['Job']="IT";
$row[2]['City']="New J";
 
$row[3]['ID']="4";
$row[3]['Name']="Anderson";
$row[3]['Email']="Anderson.com";
$row[3]['Address']="Texas";
$row[3]['Job']="IT";
$row[3]['City']="Texas";
 
$row[4]['ID']="5";
$row[4]['Name']="Kelvin";
$row[4]['Email']="Kelvin.com";
$row[4]['Address']="Cali";
$row[4]['Job']="IT";
$row[4]['City']="Cali";
 
$x = isset($_GET['ID'])?$_GET['ID']:0;
$l = count($row)-1;
$p = $x-1;
$n = $x+1;
 
echo"<form method=post>\n
ID:<input type='text' name='id' value='".$row[$x]['ID']."'><br /><br />\n
Name:<input type='text' name='name' value='".$row[$x]['Name']."'><br /><br />\n
Address:<input type='text' name='address' value='".$row[$x]['Address']."'><br /><br />\n
Job:<input type='text' name='job' value='".$row[$x]['Job']."'><br /><br />\n
City:<input type='text' name='city' value='".$row[$x]['City']."'><br /><br />\n";
 
if($x=="0")
{
    echo "Previous";
}
else
{
    echo "<a href='nextPrevious.php?ID=".$p."'>Previous</a>";
}
echo " || ";
if($x==$l)
{
    echo "Next";
}
else
{
    echo "<a href='nextPrevious.php?ID=".$n."'>Next</a>";
}
?>
[/size]

Re: MovePrevious MoveNext using links

Posted: Thu Nov 27, 2008 10:09 am
by hellboy83
I got it working :shocked!:.

Here is the entire code:

Code: Select all

<?php
include 'confgTableTest.php';
include 'opendb.php';
 
$sql ="SELECT * FROM $tbl_tableTest";
$result =mysql_query($sql);
while($line =mysql_fetch_array($result)) {
     $row[] = $line;
}
 
$x = isset($_GET['ID'])?$_GET['ID']:0;
$l = mysql_num_rows($result)-1;
$p = $x-1;
$n = $x+1;
 
echo"<form method=post>\n
ID:<input type='text' name='id' value='".$row[$x]['ID']."'><br /><br />\n
Name:<input type='text' name='name' value='".$row[$x]['Name']."'><br /><br />\n
Email:<input type='text' name='email' value='".$row[$x]['Email']."'><br /><br />\n
Address:<input type='text' name='address' value='".$row[$x]['Address']."'><br /><br />\n
Job:<input type='text' name='job' value='".$row[$x]['Job']."'><br /><br />\n
City:<input type='text' name='city' value='".$row[$x]['City']."'><br /><br />\n";
 
if($x=="0")
{
    echo "Previous";
}
else
{
    echo "<a href='nextPrevious.php?ID=".$p."'>Previous</a>";
}
echo " || ";
if($x>=$l)
{
    echo "Next";
}
else
{
    echo "<a href='nextPrevious.php?ID=".$n."'>Next</a>";
}
?>
Regards,[/size]