Hello everyone. I have really screwed up this code and can't seem to figure out all the things that is wrong with it. Can someone point me in the right direction?
Thanks!
~Amy
<?php
/* Program name: listings.php
* Description: This will pull some of the customer's information
* out of the database and display it in a table as a
* link to get further information on customer's
* property. Pagination.
*/
include ("mydatabaseinfo.txt");
$cxn = mysqli_connect ($host, $user, $password, $database)
or die ("No Connection");
//Number of records to show per page:
$display=50;
//Determine how many pages there are...
if(isset($_GET['p']) && is_numeric($_GET['p']))
{//Already been determined.
$pages=$_GET['p'];
}
else{//Need to determine.
//Count the number of records:
$county=$_GET ['county_name'];
$state=$_GET ['state'];
$q='SELECT COUNT(*) FROM Property WHERE
county=? AND state=?';
$stmt=mysqli_prepare($cxn, $q);
mysqli_stmt_bind_param($stmt,'ss', $c, $s);
$c='$county';
$s='$state';
mysqli_stmt_execute($stmt);
//Check the results:
if (mysqli_stmt_affected_rows($stmt) ==1)
{}
else { echo 'A system error occurred1';}
//Close the statement:
mysqli_stmt_close($stmt);
$row=@mysqli_fetch_array ($result, MYSQLI_NUM);
$records=$row[0];
//Calculate the number of pages...
if ($records > $display) //More than 1 page.
{
$pages=ceil ($records/$display);
}else{
$pages=1;
}
}//End of p IF.
//Determine where in the database to start returning results...
if (isset($_GET['s']) && is_numeric($_GET['s'])){
$start=$_GET['s'];
} else {
$start=0;
}
//Determine the sort...
//Default is by highest price to lowest price
$sort=(isset($_GET['sort'])) ? $_GET['sort'] : 'pr';
//Determine the sorting order:
switch ($sort) {
case 'prhl':
$order_by = 'price ASC';
break;
case 'prlh':
$order_by = 'price DESC';
break;
default:
$order_by ='price DESC';
break;
}
//Make the query:
$q='SELECT ID, Type, street, city, price, sqft FROM Homes, About Home WHERE county=? AND state=? AND active=1 ORDER BY $order_by';
$r= @mysqli_query ($cxn, $q);
$stmt=mysqli_prepare($cxn, $q);
mysqli_stmt_bind_param($stmt, 'ss', $c, $s);
$c='$county';
$s='$state';
mysqli_stmt_execute($stmt);
//Check the results:
if (mysqli_stmt_affected_rows($stmt) ==1)
{}
else { echo 'No results found!';}
$ID="ID";
$Type="Type";
$street="street";
$city="city";
$sqft="sqft";
$price="price";
//Table Header
echo "<table align=center border=1>\n";
echo "<tbody>\n";
echo "<tr><th bgColor=#add8e6>ID#</th>\n";
echo "<th bgColor=#add8e6>Type</th>\n";
echo "<th bgColor=#add8e6>Address</th>\n";
echo "<th bgColor=#add8e6>City</th>\n";
echo "<th bgColor=#add8e6>Sq Ft</th>\n";
echo "<th bgColor=#add8e6>Price</th>\n";
echo "</tr>\n";
//Fetch and print all the records...
$bg='#add8e6';//Set the initial background color
while ($row=mysqli_fetch_array($r, MYSQLI_ASSOC)){
$bg=($bg=='#add8e6' ? '#ffffff' : '#add8e6');//Switch the background color.
echo "<tr bgcolor=\"' . $bg . '\">\n";
echo "<td align=middle><a href=\"Your Place.php?ID=$ID\">$ID</a></td>\n";
echo "<td align=middle>$Type</td>\n";
echo "<td align=middle><a href=\"Your Place.php?street=$street\">$street</a></td>\n";
echo "<td align=middle>$city</td>\n";
echo "<td align=middle>$sqft</td>\n";
echo "<td align=middle><a href=\"listings.php?sort=prhl\">$price</a></td>\n";
echo "</tr>\n";
}//End of WHILE loop.
echo '<table>';
mysqli_free_result ($r);
//Make links to other pages if necessary.
if ($pages>1){
//Add some space & start a paragraph.
echo '<br /?<p>';
//Determine what page the script is on:
$current_page = ($start/$display) + 1;
//If it's not the first page, make a previous button:
if ($current_page != 1) {
echo '<a href="listings.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> ';
}
//Make all the numbered pages:
for ($i=1; $i<=$pages; $i++) {
if($i !=$current_page) {
echo '<a href="listings.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
} //End of FOR loop.
//If it's not the last page, make a next button.
if ($current_page !=$pages) {
echo '<a href="listings.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>';
}
echo '</p>';//Close paragraph.
}//End of links section.
?>