slashpine Posted December 27, 2008 Share Posted December 27, 2008 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 More sharing options...
revraz Posted December 27, 2008 Share Posted December 27, 2008 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>"; Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724233 Share on other sites More sharing options...
genericnumber1 Posted December 27, 2008 Share Posted December 27, 2008 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. Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724244 Share on other sites More sharing options...
ToonMariner Posted December 27, 2008 Share Posted December 27, 2008 OR... WTH aren't you breaking out of php to html out and using css properly to control your presentational layer???????? Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724279 Share on other sites More sharing options...
slashpine Posted December 27, 2008 Author Share Posted December 27, 2008 there is no mysql database...this parses a flat text file (CSV) Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724285 Share on other sites More sharing options...
revraz Posted December 27, 2008 Share Posted December 27, 2008 Doesn't really matter, you can still do a while loop till you get to EOF. there is no mysql database...this parses a flat text file (CSV) Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724288 Share on other sites More sharing options...
slashpine Posted December 27, 2008 Author Share Posted December 27, 2008 would it be any more difficult for you to apply it to the script I posted? I'm not a php coder and I was seeking some free syntax... I was hoping it wouldn't be too much trouble... Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724300 Share on other sites More sharing options...
slashpine Posted December 27, 2008 Author Share Posted December 27, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138516-please-hack-this-script-for-me/#findComment-724558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.