<?php

highlight_file
(__FILE__);
die();

# Connect to DB
require_once('connections/ftn.php');

# Select your DB
mysql_select_db($database_ftn$ftn); //might want to put this in your ftn.php file...

# Set your base SQL statement
$SQL 'SELECT * FROM lstng_tbl';

# Initialize the $WHERE clause holder variable
$WHERE = array();

# Check to see if you submitted a state and that it is not empty
if ( !empty($_REQUEST['state']) ) {
    
$WHERE[] = "state = '".mysql_real_escape_string($_REQUEST['state'], $ftn)."'";
}

# Check to see if you submitted a price and that it is not empty
if ( isset($_REQUEST['price']) ) {
    
$WHERE[] = "price_range = '".mysql_real_escape_string($_REQUEST['price'], $ftn)."'";
}

# Count the $WHERE array to see if I need to include the where in the SQL statement
if ( count($WHERE) > ) {
    
$SQL .= ' WHERE '.join(' AND '$WHERE);
}

# Execute Query, if error = die(), else continue on
if( ( $res mysql_query($SQL$ftn) ) === false ) {
    die(
mysql_error($ftn));
}

# Initalize the $records holder array
$records = array();

# Get the size of the result set
$total_records mysql_num_rows($res);

# Initialize some variables so they don't give us fits latter
$first $prev $next $last false;

# Did I get any results back?  Yes = Good, let figure out where I'm at and grab the 
# correct portion of the results and create the settings for the pagination links
if ( $total_records ) {

    
# How many results per page?
    
$limit_per_page 10;
    
    
# What page do you want me to start on by default?
    
$pageNum 0;

    
# Was a pageNum given to me AND is it an integer?
    
if ( is_int($_GET['pageNum']) ) {
        
# Set the pageNum to the submitted number
        #          I know, a little redundent, CYA always!!!
        
$pageNum = (int)$_GET['pageNum'];
    }

    
# Calculate the total number of pages there would be
    
$total_pages ceil$total_records $limit_per_page );

    
# See if we are on the first page, NO, then set the $first and $prev settings
        
if ( $pageNum != ) {
        
$first    TRUE;
        
$prev    = ( $current_page );
    }
    
    
# See if we are on the last page, NO, then set the $next and $last settings
    
if ( $current_page $total_pages ) {
        
$next    = ( $current_page );
        
$last    $total_pages;
    }
    
    
# Find my starting point.. I seem to recal that mysql_data_seek needs a starting 
    # point of 1 or greater, otherwise it freaks
    
$starting_point = ( ( $pageNum $limit_per_page ) + );
    
    
# Move the internal point for the result set to where we need it
    
mysql_data_seek($res$starting_point);
    
    
# Loop and grab the data
    
for ( $i $i $limit_per_page$i++ ) {
        
$records[] = mysql_fetch_assoc($res);
    }
}

# Free it all, we are done with the results...
mysql_free_result($res);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
    </head>
    <body>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <label for="states">market</label>
            <select id="states" name="states">
                <option value="">Select A State</option>
                <OPTION value="IN">Indiana</OPTION>
                <OPTION value="WI">Wisconsin</OPTION>
                <OPTION value="IL">Illinois</OPTION>
                <OPTION value="MI">Michigan</OPTION>
                <OPTION value="GA">Georgia</OPTION>
                <OPTION value="FL">Florida</OPTION>
            </select>
            <br />
            <label for="price">price_range</label>
            <select id="price" name="price">
                <option value="">Select A Price Range</option>
                <OPTION value="1">Over $2 million</OPTION>
                <OPTION value="2">$1 million - $2 million</OPTION>
                <OPTION value="3">$750,000 - $1 million</OPTION>
                <OPTION value="4">under $750,000</OPTION>
            </select>
            <input type="submit" value="Submit" />
        </form>
<?php
# See if $records has any rows, YES, display table of results
if ( count($records) > ) {
?>
        <table border="0" width="50%" align="center">
        <!-- You were missing this opening table tag.  
        I copied it from the second table.  Should match well -->
<?php
    
# Start your looping through the data set
    
foreach ( $records AS $row ) {
?>
            <tr>
                <td><?php echo $row['key']; ?></td>
                <td><?php echo $row['price_range']; ?></td>
                <td><?php echo $row['range_key']; ?></td>
                <td><?php echo $row['price']; ?></td>
                <td><?php echo $row['location']; ?></td>
                <td><?php echo $row['region']; ?></td>
                <td><?php echo $row['package']; ?></td>
                <td><?php echo $row['property_name']; ?></td>
                <td><?php echo $row['agent']; ?></td>
                <td><?php echo $row['company']; ?></td>
                <td><?php echo $row['phone_agent']; ?></td>
                <td><?php echo $row['agent_web']; ?></td>
                <td><?php echo $row['prty_descrb']; ?></td>
                <td><?php echo $row['email_agent']; ?></td>
                <td><?php echo $row['photo_1']; ?></td>
                <td><?php echo $row['Photo_2']; ?></td>
                <td><?php echo $row['Photo_3']; ?></td>
            </tr>
<?php
    
}
?>
        </table>
<?php
}
?>
        <table border="0" width="50%" align="center">
            <tr>
                <td width="25%" align="center">
                <?php echo ( ( $first !== false ) ? "<a href='{$_SERVER['PHP_SELF']}?state={$state}&price={$price}'>First</a>" '&nbsp;' ); ?>
                </td>
                <td width="25%" align="center">
                <?php echo ( ( $prev !== false ) ? "<a href='{$_SERVER['PHP_SELF']}?pageNum={$prev}&state={$state}&price={$price}'>Previous</a>" '&nbsp;' ); ?>
                </td>
                <td width="25%" align="center">
                <?php echo ( ( $next !== false ) ? "<a href='{$_SERVER['PHP_SELF']}?pageNum={$next}&state={$state}&price={$price}'>Next</a>" '&nbsp;' ); ?>
                </td>
                <td width="25%" align="center">
                <?php echo ( ( $last !== false ) ? "<a href='{$_SERVER['PHP_SELF']}?pageNum={$last}&state={$state}&price={$price}'>Last</a>" '&nbsp;' ); ?>
                </td>
            </tr>
        </table>
    </body>
</html>