Last active
December 18, 2015 11:39
-
-
Save adrianrodriguez/5777554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php include('header.php'); ?> | |
<div class="container"> | |
<div class="content row"> | |
<section id="top" class="twelve columns"> | |
<h5>Search for a Physician</h5> | |
<form action="physicians.php" method="get"> | |
<div class="field"> | |
<input type="text" name="q" class="text xwide input" placeholder="Search by: Physician, State or Zipcode"> | |
<span id="count"></span> | |
</div> | |
<input class="button" type="submit" name="submit" value="Search" /> | |
</form> | |
<p id="none" style="display:none">There were no items to match your search!</p> | |
</section> | |
<section id="physicians"> | |
<div class="return-to-top"><a href="#top"><i class="icon-up-bold"></i></a></div> | |
<div class="holder"></div> | |
<div class="clear"></div> | |
<?php | |
$user_name = "root"; | |
$password = "root"; | |
$database = "test"; | |
$server = "localhost"; | |
// $user_name = "db159009"; | |
// $password = "ICgideas306"; | |
// $database = "db159009_tpr_test"; | |
// $server = "internal-db.s159009.gridserver.com"; | |
$db_handle = mysql_connect($server, $user_name, $password); | |
$db_found = mysql_select_db($database, $db_handle); | |
if ($db_found) { | |
$perPage = 50; | |
$pageNumber = (isset($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1; //e.g. http://example.com/?page=10 | |
$offset = ($pageNumber * $perPage) - $perPage; | |
$limit = $offset + $perPage; | |
$prev = ($pageNumber - 1); | |
$next = ($pageNumber + 1); | |
$searchTerm = (isset($_GET['q'])) ? $_GET['q'] : ''; | |
$searchTerm = mysql_real_escape_string($searchTerm, $db_handle); | |
if ($searchTerm) { | |
$sql = "SELECT COUNT(*) FROM doctors WHERE city like '%{$searchTerm}%' OR state like '%{$searchTerm}%' OR zip like '%{$searchTerm}%' OR name like '%{$searchTerm}%'"; | |
} else { | |
$sql = "SELECT COUNT(*) FROM doctors"; | |
} | |
$result = mysql_query($sql); | |
$total = mysql_fetch_row($result); | |
print 'Total # of Records: ' . $total[0]; | |
$numPages = ceil($total[0] / $perPage); | |
if ($searchTerm) { | |
$sql = "SELECT * FROM doctors WHERE city like '%{$searchTerm}%' OR state like '%{$searchTerm}%' OR zip like '%{$searchTerm}%' OR name like '%{$searchTerm}%' ORDER BY state LIMIT {$offset}, {$limit}" ; | |
} else { | |
$sql = "SELECT * FROM doctors ORDER BY state LIMIT {$offset}, {$limit}" ; | |
} | |
$result = mysql_query($sql); | |
$pagination = ''; | |
if($pageNumber > 1) | |
{ | |
$pagination .= '<a class="prev" href="physicians.php?q=' . $searchTerm . '&page='.$i.'">Previous</a>'; | |
} | |
for($i = max(1, $pageNumber -5); $i <= min($pageNumber + 5, $numPages); $i++) | |
{ | |
if(($pageNumber) == $i) | |
{ | |
$pagination .= $i; | |
} | |
else | |
{ | |
$pagination .= '<a class="page-link" href="physicians.php?q=' . $searchTerm . '&page=' . $i . '">' . $i .'</a>'; | |
} | |
} | |
/* Print NEXT link if there is one */ | |
if($pageNumber < $numPages) | |
{ | |
$pagination .= '<a class="next" href="physicians.php?q=' . $searchTerm . '&page='.$next.'"> Next</a>'; | |
} | |
echo '<div class="pagination">' . $pagination .'</div><div class="clear"></div><ul class="two_up tiles">'; | |
while ( $db_field = mysql_fetch_assoc($result) ) { | |
print "<li class='physician column-row'> <h5>" . $db_field['practice'] . "</h5> | |
<p class='physician_name'> <strong>Physician:</strong> " . $db_field['name'] . ", " . $db_field['title'] . "</p> | |
<p><strong>Specialty:</strong> " . $db_field['specialty'] . "</p> | |
<p><strong>Address: </strong><a target='_blank' class='physician_address' href=''>" . $db_field['address']. " | |
<br />" . $db_field['city'] . ", " . $db_field['state'] . " " . $db_field['zip'] . "</a></p> | |
<p class='physican_phone'><i class='icon-phone'></i><a href='tel:'>" . $db_field['phone'] . "</a></p> | |
<p><i class='icon-globe'></i><a target='_blank' class='physician_web' href=''>" . $db_field['web'] . "</a></p></li>"; | |
} | |
echo '</ul><div class="clear"></div> <div class="pagination">' . $pagination .'</div>'; | |
mysql_close($db_handle); | |
} | |
else { | |
print "Database NOT Found "; | |
} | |
?> | |
</section> | |
<div class="clear"></div> | |
</div> | |
</div> | |
<?php include('footer.php'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment