Jump to content

please hack this script for me...


slashpine

Recommended Posts

I am trying to add both column headings and alternating color rows to this script...can a php coder please code in an example of both in this script?

 

Thanks

<?php

$filename = "file.csv";

function viewlog($filename) {
$fp = fopen($filename,"r");
$file = fread($fp,65535);
$replaced = eregi_replace(",", "<td>", $file);
$replaced2 = eregi_replace("\n", "<tr><td>", $replaced);
$replaced3 = eregi_replace("\r", "<tr><td>", $replaced2);
fclose($fp);

return $replaced3;
}
echo "<html><head><title></title></head><body bgcolor=silver>";
echo "<table border=1 bordercolor=black cellspacing=0 cellpadding=5 width=100% style='font-size:10pt'>";

echo viewlog($filename);
echo "</table></body></html>";
exit;
?>

Link to comment
https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/
Share on other sites

Here is one way to do alternate row colors, not specific to your code, but easy to integrate.

 

$color = "#ffffff";
$color1 = "#ffffff";
$color2 = "#99ffff";
while ($row = mysql_fetch_row($result))
		{
		 			if ($color == $color1){
					$color = $color2;
					}ELSE{
					$color = $color1;
					}
					$id=$row[0];
					echo "<tr bgcolor=$color>";

Or...

 

<?php
$colors = array('#ffffff', '#99ffff');
$count = count($colors);
$iter = 0;

while($row = mysql_fetch_array($result)) {
   echo '<tr style="background-color:' . $colors[$iter % $count] . '">';
   ++$iter;
}

 

allows for a variable amount of colors beyond 2, all you need to do is add it to the array.

I am trying to add both column headings and alternating color rows to this script...can a php coder please code in an example of both in this script?

 

Thanks

<?php

$filename = "file.csv";

function viewlog($filename) {
$fp = fopen($filename,"r");
$file = fread($fp,65535);
$replaced = eregi_replace(",", "<td>", $file);
$replaced2 = eregi_replace("\n", "<tr><td>", $replaced);
$replaced3 = eregi_replace("\r", "<tr><td>", $replaced2);
fclose($fp);

return $replaced3;
}
echo "<html><head><title></title></head><body bgcolor=silver>";
echo "<table border=1 bordercolor=black cellspacing=0 cellpadding=5 width=100% style='font-size:10pt'>";

echo viewlog($filename);
echo "</table></body></html>";
exit;
?>

 

I have been able to add column headings but I am still unable to get the alternating row color to work

...can someone please show me hos this can be down witht the existing code?

 

Also...(more of a php question) how would I remove a couple of the records in the CSV file NOT to display?

 

Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.