Hello, i'm really drawing a blank on how to do this better. Basically the code below pulls a record from the db then lets the user cycle through them with back and next buttons. However my way seems brutish and far from elegant and functional. Can i get some pointers on a better way of doing this?
<?php
if($_GET['action'] == "entercountyclerk")
{
$link = mysql_connect("localhost", "username", "password") or die("Could not connect to database");
mysql_select_db("fndb", $link) or die("Could not select database");
$from = $_POST['from'];
$to = $_POST['to'];
if($_POST['submit'] == "Next")
{
$filenum = $_POST['filenum'];
$id = $_POST['id'];
$filedate = date("Y-m-d", strtotime($_POST['filedate']));
mysql_query("UPDATE fictitiousnamedb SET filenum = '$filenum', filedate = '$filedate' WHERE id='$id'") or die (mysql_error());
$from++;
$to++;
}
elseif($_POST['submit'] == "Back")
{
$from--;
$to--;
}
else
{
$from = 0;
$to = 1;
}
if($_POST['viewall'] == 'true')
{
$now = date("Y-m-d");
$result = mysql_query("SELECT * FROM fictitiousnamedb WHERE rununtil > $now ORDER BY date DESC LIMIT $from , $to", $link) or die (mysql_error());
}
else
{
$result = mysql_query("SELECT * FROM fictitiousnamedb WHERE filenum = '' ORDER BY date DESC LIMIT $from , $to", $link) or die (mysql_error());
}
list($id,$filenum,$filedate,$date,$rununtil,$mailname,$mailaddress,$mailcity,$mailstate,$mailzip,$mailtelephone,$fbn1,$ainum,$conductedby,$commencedtransaction,$commencedtransactiondate) = mysql_fetch_row($result);
if(mysql_num_rows($result) == 0) echo "All records seem to be up to date";
?>
<?php echo $mailname; ?> <br>
<?php echo $mailaddress; ?> <br>
<?php echo $mailcity; ?> <br>
<?php echo $mailstate; ?>
<?php echo $mailzip; ?> <br>
<?php echo $mailtelephone; ?> <br>
<?php echo $fbn1; ?> <br>
<?php //echo $filedate; ?> <br>
<?php if($filedate == 00000000000000) $filedate = date("F j, Y", strtotime("Tuesday"));
else $filedate = date("F j, Y",strtotime($filedate));?>
<form method="post" action="<?php $PHP_SELF ?>">
County Clerk Filing Number: <input type ="text" name ="filenum" size ="20" value="<?php echo $filenum; ?>"><br>
County Clerk Filing Date: <input type ="text" name ="filedate" size ="20" value="<?php echo $filedate; ?>"><br>
<input type="hidden" name="from" value="<?php echo $from; ?>">
<input type="hidden" name="to" value="<?php echo $to; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="submit" value="Back">
<input type="submit" name="submit" value="Next">
<input type="checkbox" name="viewall" value="true" <?php if($_POST['viewall'] == 'true') echo "checked"; ?>>View all records for this printing</form>
<?php
mysql_free_result($result);
mysql_close();
}
?>
Let me know if i can clear anything up for you. Thanks for any and all help.
-emrys