1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

MovePrevious MoveNext using links

Discussion in 'PHP' started by hellboy83, Nov 26, 2008.

  1. #1
    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?

    <?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>
    PHP:
    Regards,
     
    hellboy83, Nov 26, 2008 IP
  2. hellboy83

    hellboy83 Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I got it working :shocked!:.

    Here is the entire code:
    <?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>";
    }
    ?>
    PHP:
    Regards,
     
    hellboy83, Nov 27, 2008 IP