Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2015, 10:46 PM
pityocamptes's Avatar
pityocamptes pityocamptes is offline
 
Join Date: Apr 2010
Posts: 595
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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>";

?>
Reply With Quote
  #2  
Old 05-21-2015, 12:42 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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;
Attached Images
File Type: jpg bank.jpg (113.6 KB, 0 views)
Reply With Quote
  #3  
Old 05-21-2015, 01:53 AM
pityocamptes's Avatar
pityocamptes pityocamptes is offline
 
Join Date: Apr 2010
Posts: 595
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>";
}

?>
Reply With Quote
  #4  
Old 05-21-2015, 02:59 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>";
}

?>
Reply With Quote
  #5  
Old 05-21-2015, 03:01 AM
pityocamptes's Avatar
pityocamptes pityocamptes is offline
 
Join Date: Apr 2010
Posts: 595
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
--------------- Added [DATE]1432184580[/DATE] at [TIME]1432184580[/TIME] ---------------

Quote:
Originally Posted by Replicant View Post
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>";
}

?>


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!
Reply With Quote
  #6  
Old 05-21-2015, 03:09 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Благодарность от:
RichieBoy67
  #7  
Old 05-21-2015, 03:10 AM
pityocamptes's Avatar
pityocamptes pityocamptes is offline
 
Join Date: Apr 2010
Posts: 595
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #8  
Old 05-21-2015, 03:17 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 05-21-2015, 03:43 AM
pityocamptes's Avatar
pityocamptes pityocamptes is offline
 
Join Date: Apr 2010
Posts: 595
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>";
}

?>
Reply With Quote
  #10  
Old 05-21-2015, 04:37 AM
Replicant's Avatar
Replicant Replicant is offline
 
Join Date: Sep 2014
Location: Phoenix, Az. USA
Posts: 485
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:16 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06823 seconds
  • Memory Usage 2,298KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (8)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete