I am trying to make a small web application with PHP and I have finally managed to get the script to pickup the first row in a table in the database and then select the next and previous rows giving the ability to cycle through all of the records while displaying each row in a form.
On one of my pages I need to collect the data from a row (Identified by a field called 'caleadID') in table(A) and then insert into another table(B). I have managed to get this data and insert into the table(B). After the data has been inserted into the table(B) it redirects me to another page and displays the data I just inserted in a form, I have a next and previous button on this page to cycle through the rows of table(B) similar to the other page. The next and previous buttons don't work as they should.
Any help would be well appreciated!
$page = intval($_GET['page']);
$limitStart = $page - 1;
if($limitStart < 0) {
$limitStart = 0;
}
if(isset($_GET['caleadID'])) {
$caleadID = $_GET['caleadID'];
$query = "SELECT caleadID, region, siteaddr1, siteaddr2, siteaddr3, siteaddr4, sitepcode, ";
$query .= "addgennotes, description, value, award, awardaddr1, awardaddr2, awardaddr3, awardaddr4, awardpcode, ";
$query .= "phone_number, fax_number, fldAwardedWebsite, fldAwardedEmail, contact_name, date FROM tblLeads_Awarded WHERE ";
$query .= "caleadID = '" . $caleadID . "'";
$query .= " LIMIT " . $limitStart . ',3';
$result = mysqli_query($connection, $query);
confirm_query($result);
}
else
{
$query = "SELECT caleadID, region, siteaddr1, siteaddr2, siteaddr3, siteaddr4, sitepcode, ";
$query .= "addgennotes, description, value, award, awardaddr1, awardaddr2, awardaddr3, awardaddr4, awardpcode, ";
$query .= "phone_number, fax_number, fldAwardedWebsite, fldAwardedEmail, contact_name, date FROM tblLeads_Awarded WHERE 1";
$query .= " LIMIT " . $limitStart . ',3';
$result = mysqli_query($connection, $query);
confirm_query($result);
}
$result_array = array();
while($row = mysqli_fetch_assoc($result)) {
$result_array[] = $row;
}
if(intval($page) === 0) {
$previousRecord = NULL;
$currentRecord = $result_array[0];
$nextRecord = $result_array[1];
}
else
{
$previousRecord = $result_array[0];
$currentRecord = $result_array[1];
$nextRecord = $result_array[2];
}
if($previousRecord) {
$prevPage = $page - 1;
if($prevPage < 0) {
$pagePage = 0;
}
$prevLink = 'view_leads.php?page=' . $prevPage;
}
if($nextRecord) {
$nextLink = 'view_leads.php?page=' . ($page + 1);
}
?>
<div id="tradesmen_data_navigation">
<a href="<?PHP echo $prevLink ?>"><input type="submit" name="previous" value="Previous Record" /></a>
<a href="<?PHP echo $nextLink ?>"><input type="submit" name="next" value="Next Record" /></a>
</div>