-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rudimentary functionality to create legislators menu
Toward #296, this is really basic functionality that will create the legislators menu. It's not grouping alphabetically (that's going to require some thinking), but it's a start.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* Generate Legislators Menu | ||
* | ||
* Query the database to generate a list of all legislators, to update the menu. | ||
* The resulting list is sent to stdout. | ||
**/ | ||
|
||
$database = new Database; | ||
$db = $database->connect_mysqli(); | ||
|
||
/* | ||
* Get a list of all legislators. | ||
*/ | ||
$sql = 'SELECT name_formatted, shortname, chamber | ||
FROM representatives | ||
WHERE date_ended IS NOT NULL OR date_ended >= now() | ||
ORDER BY chamber ASC, name ASC'; | ||
$result = mysqli_query($db, $sql); | ||
|
||
$legislators = array('house' => array(), 'senate' => array()); | ||
|
||
/* | ||
* Build up an HTML-formatted array of legislators by chamber. | ||
*/ | ||
while ($legislator = mysqli_fetch_assoc($result)) | ||
{ | ||
|
||
$legislator = array_map('stripslashes', $legislator); | ||
$legislators[$legislator{'chamber'}][] = '<li><a href="/legislator/' . $legislator['shortname'] | ||
. ' /">' . $legislator . '</a></li>'; | ||
|
||
} | ||
|
||
/* | ||
* | ||
*/ | ||
echo ' | ||
<ul> | ||
<li>House » | ||
<ul class="alphabetic"> | ||
<li>A–Z » | ||
<ul class="legislators"> | ||
' . implode("\t", $legislators['house']) . ' | ||
</ul> | ||
</li> | ||
</ul> | ||
</li> | ||
<li>Senate » | ||
<ul class="alphabetic"> | ||
<li>A–Z » | ||
<ul class="legislators"> | ||
' . implode("\t", $legislators['senate']) . ' | ||
</ul> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul>'; |