The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Help on converting CSV to HTML for Widget
I'm looking to get the printout of this file into the main forum side boxes (widget). I have this code and it seems to work when running in php, but completely screws up the widget box when pasting into the forum manager boxes. Can anyone take a look at it and help me out? Thanks.
Code:
<?php echo "<html><body><table>nn"; $f = fopen("https://www.fdic.gov/bank/individual/failed/banklist.csv", "r"); while (($line = fgetcsv($f)) !== false) { echo "<tr>"; foreach ($line as $cell) { echo "<td>" . htmlspecialchars($cell) . "</td>"; } echo "</tr>n"; } fclose($f); echo "n</table></body></html>"; ?> |
#2
|
||||
|
||||
I was able to get this to work, however I had to adjust the sideblock width to 1350 px to accomadate the width of the table. Your code was fine, you just need to return the html to the widget instead of echo.
Code:
ob_start(); echo '<table>'; $f = fopen("https://www.fdic.gov/bank/individual/failed/banklist.csv", "r"); while (($line = fgetcsv($f)) !== false) { echo '<tr>'; foreach ($line as $cell) { echo '<td>' . htmlspecialchars($cell) . '</td>'; } echo '</tr>'; } fclose($f); echo '</table>'; $html = ob_get_clean(); return $html; |
#3
|
||||
|
||||
Thanks. I have this code to drop rows that I do not need, [2], [3],[6]. Which I was able to do in this code, however, I would like to offset each row with a different color (horizontally) and the arrays seem to be populating the table vertically (along with color)... thoughts? Thanks.
For some reason the color for the offset "row" colors is not coming out right in html - when it displays. Its been a while since I've coded, please feel free to give advice or clean up suggestions... thanks. Code:
<?php $count = 1; $input = 'https://www.fdic.gov/bank/individual/failed/banklist.csv'; echo "<html><body><table border=1 width=250>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Bank Name</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>City</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Acq. Institution</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Closing Date</FONT></th>"; if (false !== ($ih = fopen($input, 'r'))) { fgetcsv($ih); while (false !== ($data = fgetcsv($ih))) { $outputData = array($data[0], $data[1], $data[4], $data[5]); echo "<tr>"; foreach ($outputData as $row) { if($count % 2 == 0) $rowColor = '#0066FF'; else $rowColor = '#222937'; echo "<td bgcolor= .$rowColor.><FONT COLOR=D3AB04 FACE=Geneva, Arial SIZE=2>" . htmlspecialchars($row) . "</FONT></td>"; $count++; } } fclose($ih); echo "</table></body></html>"; } ?> |
#4
|
||||
|
||||
I added a class to the rows and use CSS to color the backgrounds. You could add a class for the TD tags as well and use CSS to set the font and color too.
Code:
<?php $count = 1; $input = 'https://www.fdic.gov/bank/individual/failed/banklist.csv'; echo "<html><body><table border=1 width=250>"; echo "<style> tr.row:nth-child(odd) { background: blue; } tr.row:nth-child(even) { background: black; } </style>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Bank Name</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>City</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Acq. Institution</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Closing Date</FONT></th>"; if (false !== ($ih = fopen($input, 'r'))) { fgetcsv($ih); while (false !== ($data = fgetcsv($ih))) { $outputData = array($data[0], $data[1], $data[4], $data[5]); echo "<tr class=row >"; foreach ($outputData as $row) { echo "<td ><FONT COLOR=D3AB04 FACE=Geneva, Arial SIZE=2>" . htmlspecialchars($row) . "</FONT></td>"; $count++; } } fclose($ih); echo "</table></body></html>"; } ?> |
#5
|
||||
|
||||
I was getting help from stack overflow. This looks like it might work, have not tried it yet. The poster indicated that code needs to be changed to get this to work in a widget. What do I need to change in the following code to get it to work, along with where to I place the css file (additional.css)??? Thanks.
Code:
<?php $count = 0; $input = 'https://www.fdic.gov/bank/individual/failed/banklist.csv'; echo "<html><body><table width='250' class='TFtable' >"; echo "<tr>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE SIZE=3>Bank Name</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE SIZE=3>City</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE SIZE=3>Acq. Institution</FONT></th>"; echo "<th bgcolor=#222937><FONT COLOR=WHITE SIZE=3>Closing Date</FONT></th>"; echo "</tr>"; if (false !== ($ih = fopen($input, 'r'))) { fgetcsv($ih); while (false !== ($data = fgetcsv($ih))) { $outputData = array($data[0], $data[1], $data[4], $data[5]); echo "<tr>"; foreach ($outputData as $row) { echo "<td><FONT COLOR=D3AB04 SIZE=2>" . htmlspecialchars($row) . "</FONT></td>"; $count++; } echo "</tr>"; } fclose($ih); echo "</table></body></html>"; } ?> Code:
<style type="text/css"> .TFtable{ width:100%; border-collapse:collapse; } .TFtable td{ padding:7px; border:#4e95f4 1px solid; } /* provide some minimal visual accomodation for IE8 and below */ .TFtable tr{ background: #b8d1f3; } /* Define the background color for all the ODD background rows */ .TFtable tr:nth-child(odd){ background: #b8d1f3; } /* Define the background color for all the EVEN background rows */ .TFtable tr:nth-child(even){ background: #dae5f4; } </style> Quote:
Ok, thanks. That is what someone on stackoverflow did. Could you please let me know what I need to change in the above code to get it to work in the widget? You mentioned something about the object? Also, how do I get the css to work? Thanks again! --------------- Added [DATE]1432184792[/DATE] at [TIME]1432184792[/TIME] --------------- Hey that worked nice!!! How do I get rid of the borders? ALso, what do I need to change in the code to get it to run in a widget? Thanks again! |
#6
|
||||
|
||||
Remove the php, body, and html tags, wrap it up in a object like on post 2 and return the object string. Put the CSS in the additional.css or you can write it straight into style tags if you want.
|
Благодарность от: | ||
RichieBoy67 |
#7
|
||||
|
||||
Is it possible to add this to the code to get it to scroll? Thanks.
var $table = $('table.scroll'), $bodyCells = $table.find('tbody tr:first').children(), colWidth; // Adjust the width of thead cells when window resizes $(window).resize(function() { // Get the tbody columns width array colWidth = $bodyCells.map(function() { return $(this).width(); }).get(); // Set the width of thead columns $table.find('thead tr').children().each(function(i, v) { $(v).width(colWidth[i]); }); }).resize(); // Trigger resize handler |
#8
|
||||
|
||||
That code as-is looks like it will affect all tables on the page. Just looking at it without testing it, it looks like it will work. Add some script tags to it and throw it in an ad block and give it a try. You may have to use the TFtable selector to have the JS only affect the table you're working on.
|
#9
|
||||
|
||||
Thanks again! I am trying to add a header at the top, which would remain static, allowing the table to scroll under it. I can't seem to get it to work, and for some reason the header at the top is not the same width as the table below even though both are set to 250 for width...
Code:
<div> <table style=border: none; border-collapse: collapse; border=0 cellspacing=0 cellpadding=0 align=center width=250> <tr> <th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Bank Name</FONT></th> <th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>City</FONT></th> <th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Acq. Institution</FONT></th> <th bgcolor=#222937><FONT COLOR=WHITE FACE=Geneva, Arial SIZE=3>Closing Date</FONT></th> </tr> </table> </div> <?php $count = 1; $input = 'https://www.fdic.gov/bank/individual/failed/banklist.csv'; echo "<style> tr.row:nth-child(odd) { background: blue; } tr.row:nth-child(even) { background: black; } table.tBorder{ width:250; /* or what you need it to be */ height: auto; /* make this the size you want the data to be displayed in */ overflow: auto; /* this adds the scroll bars to the div when any data exceeds its hieght */ } td.border{ width: 50%; border-top: 1px solid #000000; border-bottom: 0px solid #000000; /* move spacing to the cell */ } </style>"; echo "<html><body><table class=tBorder style=border: none; border-collapse: collapse; border=0 cellspacing=0 cellpadding=0 align=center width=250>"; if (false !== ($ih = fopen($input, 'r'))) { fgetcsv($ih); while (false !== ($data = fgetcsv($ih))) { $outputData = array($data[0], $data[1], $data[4], $data[5]); echo "<tr class=row >"; foreach ($outputData as $row) { echo "<td class=border align=center ><FONT COLOR=D3AB04 FACE=Geneva, Arial SIZE=2>" . htmlspecialchars($row) . "</FONT></td>"; $count++; } } fclose($ih); echo "</table></body></html>"; } ?> |
#10
|
||||
|
||||
What you're trying to do with the scrolling feature and fixed header can be done with CSS. There's no reason to bring javascript into the picture for something this simple. Google "CSS table fixed header". You should find tons of examples to go by.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|