Skip to content

Commit

Permalink
Add rudimentary functionality to create legislators menu
Browse files Browse the repository at this point in the history
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
waldoj committed Jul 22, 2019
1 parent 6d66341 commit ac7d757
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions deploy/generate-menu.php
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>';

0 comments on commit ac7d757

Please sign in to comment.