I've taken a bit of a hiatus from PHP once I discovered that my webhost didn't support mysqli, and that's how I had learned it. Needless to say, I'm back. Now I'm trying to learn PHP with MySql. I need to create a script that will search a database and automatically provide links to the next record.
I have taken some steps, and even managed to make it work in a roundabout way. Here is my code:
Code: Select all
<?php
// Call includes
include("./includes/inc.php");
// Connect to DB
$conn = dbconn();
// Gets ID from URL
if (!$_GET['id']) {
$f = 0;
} else {
$f = $_GET['id'];
}
// Sets the second number for the limit query.
$s = 1;
$qry = "select * from office where Deleted='0' limit $f,$s";
$result = mysql_query($qry);
if (!$result)
{
die ("Could not query the database: <br />". mysql_error());
}
while($row = mysql_fetch_array($result)){
$id = $row['C_ID'];
$title = $row['Title'];
$loan = $row['LoanAmt'];
$borr = $row['Borrower'];
$term = $row['Term'];
$amort = $row['Amortization'];
}
echo <<<HTML
This entry has the ID of $id<br />
Title: $title <br />
Loan: $loan <br />
Borrower: $borr<br />
Term: $term <br />
Amortization: $amort<br />
<a href="./test.php?id=$id">Next</a>
HTML;
?>Code: Select all
CREATE TABLE `office` (
`C_ID` int(25) NOT NULL auto_increment COMMENT 'The ID of the entry',
`Deleted` tinyint(1) NOT NULL default '0' COMMENT 'Checks to see if the entry is to appear',
`Title` varchar(99) NOT NULL default '' COMMENT 'The title to appear on the page',
`LoanAmt` varchar(25) NOT NULL default '' COMMENT 'The loan amount',
`Borrower` varchar(99) NOT NULL default '' COMMENT 'Who borrowed it?',
`Term` varchar(20) NOT NULL default '' COMMENT 'The term of the loan',
`Amortization` varchar(20) NOT NULL default '' COMMENT 'Length of amortization period',
PRIMARY KEY (`C_ID`),
UNIQUE KEY `C_ID` (`C_ID`,`Title`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;I know the code is really messy, but I work in steps. It's missing code to find out if it's the first record, and doesn't stop the 'next' link from being displayed on the last record. Again, it's a work in process.
I would appreciate any help I can get here, as I'm a little lost.
Abs