Elections by State


[insert_php]

$searchTerm=isset($_POST[‘searchTerm’])? trim($_POST[‘searchTerm’]) : “All Cities”;
echo “

    ” . $searchTerm . “

“;
//connect to the database
$db=mysqli_connect(“127.0.0.1”, “uscm”, “QfqKmrOv2OmqgKUzKSV3”, “wp_uscm”) or die (‘I cannot connect to the database because: ‘ . mysql_error());
//-query the database table
$date = “2017”;
$sql=”SELECT * from mv_mayors WHERE ElectionDate LIKE ‘$date%’ “;
if($searchTerm != “All Cities”) {
$sql .= “AND State = ‘” . $searchTerm. “‘ “;
}
$sql .= “Order by ElectionDate, State, City”;
//-run the query against the mysql query function
$result=mysqli_query($db, $sql);
//-create while loop and loop through result set
while($row=mysqli_fetch_array($result)){
$City=$row[‘City’];
$State=$row[‘State’];
$FullName=$row[‘FullName’];
$ElectionDate=$row[‘ElectionDate’];
//-display the result of the array
echo “

“;
}
[/insert_php]

Mayor City State Election Date
” . $FullName . “ ” . $City. “ ” . $State . “ ” . $ElectionDate . “