Last active
September 14, 2015 14:26
-
-
Save deepak-rajpal/52a12f59d935a51678fb to your computer and use it in GitHub Desktop.
Creating Unique dropdown list of Interest Rates (from XML), Creating Unique table (with content/rows) for each Interest Rate and then display table depending on the selected rates from dropdown
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
<!-- Create Interest Rates Dropdown. Selecting any rate will display table of that interest rate data --> | |
<select name="interestItems" id="interestItems" class="styledGrayMedium" selected="selected"> | |
<option value="All">All</option> | |
<?php | |
$rate_type_list = array(); | |
if ($xml) { | |
foreach ($xml->children() as $second_gen) { | |
foreach ($second_gen->children() as $third_gen) | |
{ | |
// 2 ways to collect different interst rate types 1) using $third_gen->type or extract from $third_gen->name | |
// $RateItem_type = $third_gen->type; | |
$RateItem_name = $third_gen->name; | |
// array_push($rate_type_list,$RateItem_type); | |
$RateItem_type = substr(strrchr($RateItem_name, " "), 1); | |
array_push($rate_type_list,$RateItem_type); | |
} | |
} | |
} | |
$unique_rate_type = array_unique ($rate_type_list); | |
asort($unique_rate_type); | |
foreach ($unique_rate_type as $rate_type) { | |
echo "<option val='$rate_type'>$rate_type</option>"; | |
} | |
?> | |
</select> |
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
<script> | |
$('#interst_rate_container').ready(function(){ | |
var selectedItem = $('#interestItems').val(); | |
$('#All').css("display", "block"); | |
}); | |
$('#interestItems').change(function(){ | |
$('.interest_rate_box').css("display", "none"); | |
var selectedItem = $('#interestItems').val(); | |
var selectedRateTable = '#'+selectedItem; | |
$(selectedRateTable).css("display", "block"); | |
// alert(selectedRateTable); | |
$('span#selectinterestItems').text(selectedItem); | |
//$(selectedDiv+" .titleDataTable th").text(selectedItem); | |
}); | |
</script> |
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
<InterestRateResult> | |
<InterestRates> | |
<InterestRate> | |
<name>Russian Rouble 1 Year MOWIBOR</name> | |
<ricSymbol>MOWRUB6M_1YD=</ricSymbol> | |
<last>13.510</last> | |
<change>13.510</change> | |
<percentChange>0.00</percentChange> | |
<lastUpdate>12:00 AM 1/1/0001</lastUpdate> | |
<type>MOWIBOR=</type> | |
</InterestRate> | |
<InterestRates> | |
<InterestRate> | |
<name>Russian Rouble 1 Year MOWIBOR</name> | |
<ricSymbol>MOWRUB6M_1YD=</ricSymbol> | |
<last>13.510</last> | |
<change>13.510</change> | |
<percentChange>0.00</percentChange> | |
<lastUpdate>12:00 AM 1/1/0001</lastUpdate> | |
<type>MOWIBOR=</type> | |
</InterestRate> | |
</InterestRateResult> | |
<InterestRates> |
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
<!-- -------------- Starts: Creating a table for each unique Interest Rate ------------------- --> | |
<?php | |
$xml_data = curl($feed_url); | |
// If you have xml data in another page, use simplexml_load_file(), and if you have in variable use SimpleXMLElement() | |
// $xml = simplexml_load_file($feed_url); | |
$xml = new SimpleXMLElement($xml_data); | |
$count = 0; | |
foreach ($xml->children() as $second_gen) { | |
foreach ($second_gen->children() as $third_gen) | |
{ | |
$RateItem_name = $third_gen->name; | |
$RateItem_last = $third_gen->last; | |
$RateItem_change = $third_gen->change; | |
$RateItem_lastUpdate = $third_gen->lastUpdate; | |
//$RateItem_type = $third_gen->type; | |
//array_push($rate_type_list,$RateItem_type); | |
//$RateItem_type = trim($RateItem_type,"="); | |
$RateItem_type = substr(strrchr($RateItem_name, " "), 1); | |
if ($RateItem_change < 0) { $change_Class = "maroontext"; } else { $change_Class = "greentext"; } | |
//if !isset($current_table_id) { $count = 0; } // Check if first item and assign rate type based on that | |
if ($count == 0) { | |
$current_table_id = $RateItem_type; | |
// $table_needed = 1; // 1 = Table need to created | |
} else if ($current_table_id != $RateItem_type) { | |
$current_table_id = $RateItem_type; | |
$table_needed = 1; | |
} else { $table_needed = 0; } | |
?> | |
<?php | |
// Starts Table for the first time only | |
if ($count == 0) { ?> | |
<div style="display:none;" id="<?php echo $current_table_id; ?>" class="dataTable greybrdr interest_rate_box"> | |
<table cellspacing="0" cellpadding="5" class="titleDataTable lightbluebg ar"> | |
<tbody><tr> | |
<th></th> | |
<th>Last</th> | |
<th>Change(%)</th> | |
<th>Last Update</th></tr> | |
</tbody></table> | |
<div class="scrolltbl scrollbarTr"> | |
<table> | |
<tbody> | |
<?php } | |
// Ends first time table creation | |
// Start New Rate type case: Close existing table and start a new one for each New Rate type | |
if ($table_needed == 1) { | |
?> | |
</tbody> | |
</table> | |
</div> | |
</div> | |
<div style="display:none;" id="<?php echo $current_table_id; ?>" > | |
<table> | |
<tbody><tr> | |
<th></th> | |
<th>Last</th> | |
<th>Change(%)</th> | |
<th>Last Update</th></tr> | |
</tbody></table> | |
<div> | |
<table> | |
<tbody> | |
<?php } | |
// Ends New Rate type case: Close existing table and start a new one for each New Rate type | |
// Adds Rows (Interest Rates Information & Content) | |
?> | |
<tr class="bbrdr"> | |
<td width="45%" class="txtalleft"> | |
<a style="font-size:11px;"><?php echo $RateItem_name; ?></a> | |
</td> | |
<td width="15%" class="txtallright"><?php echo $RateItem_last; ?></td> | |
<td width="15%" class="txtallright <?php echo $change_Class; ?>"><?php echo $RateItem_change; ?></td> | |
<td width="25%" class="txtallright"><?php echo $RateItem_lastUpdate; ?></td> | |
</tr> | |
<?php | |
$count = 1; | |
} } | |
?> | |
<!-- Close Table after all loops done --> | |
</tbody> | |
</table> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment