phpgru Posted May 28, 2007 Share Posted May 28, 2007 greetings guys I found this forum really good.last time i was having the same problem but it solved all is left to formate the out put.im taking few input from page and mean while it is displaying the out put below and i want to put the display below in a tubular format rite now it is not in tabular formate. <?php if(isset($_POST['check'])){ $check = $_POST['check']; if($check == '1'){ $mac = $_POST['mac']; $ip = $_POST['ip']; $user = $_POST['user']; $adate = $_POST['adate']; $bdate = $_POST['bdate']; $fh = fopen('ATT00012.txt','ab'); fwrite($fh, "$mac $ip $user $adate $bdate |\n"); fclose($fh); } } ?> <html> <head> <title>User Details</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body bgcolor="#FF9900"> <form name="subform" action="add.php" method="post"> <input type="hidden" name="check" value="1"> <table width="364" border="1" align="center"> <tr> <td width="174"><div align="center"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">MAC ADDRESS</font></strong></font></div></td> <td width="174"><div align="center"> <INPUT type="text" name="mac"> </div></td> </tr> <tr> <td><div align="center"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">IP ADDRESS</font></strong></font></div></td> <td><div align="center"> <INPUT type="text" name="ip"> </div></td> </tr> <tr> <td><div align="center"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">USERNAME</font></strong></font></div></td> <td><div align="center"> <INPUT type="text" name="user"> </div></td> </tr> <tr> <td><div align="center"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">ACTIVATE DATE</font></strong></font></div></td> <td><div align="center"> <INPUT type="text" name="adate"> </div></td> </tr> <tr> <td><div align="center"><font size="2"><strong><font face="Verdana, Arial, Helvetica, sans-serif">BLOCK DATE</font></strong></font></div></td> <td><div align="center"> <INPUT type="text" name="bdate"> </div></td> </tr> <tr> <td colspan="2"><div align="center"> <INPUT type="submit" name="submit" value="Submit"> </div></td> </tr> </table> </form> <hr> <br> <?php $fh = fopen('ATT00012.txt','rb'); for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) { $line = trim($line); $info = explode('|', $line); print '' . $info[0] . "<br><br>"; } fclose($fh); ?> <p> </p><p> </p></body> </html> here is the script all i want to know to formate the display which will appear below page which contains this info # MAC ADDRESS IPADDRESS USERNAME ACTIVTE DATE BLOCK DATE| 00:06:5b:4a:20:a1 10.100.28.1 Rogers comm. 15/05/2007 | 00:16:76:21:b0:91 10.100.28.2 Shaheer khan 15/05/2007 | 4c:00:10:60:cd:2e 10.100.28.3 Imaad 15/05/2007 | 00:08:02:d3:4a:ef 10.100.28.4 Hassan 15/05/2007 | 00:09:6b:38:91:0b 10.100.28.5 Hamza bakaiy 15/05/2007 | 00:c0:26:78:06:61 10.100.28.6 Farhan fahim 15/05/2007 17/05/2007 | 00:50:04:d6:fc:95 10.100.28.7 Aamir 15/05/2007 | looking forward for your kind response. Regards Net_Spy Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/ Share on other sites More sharing options...
phpgru Posted May 28, 2007 Author Share Posted May 28, 2007 here is the correct formate from which the data will be read and write. # MAC ADDRESS IPADDRESS USERNAME ACTIVTE DATE BLOCK DATE| 00:06:5b:4a:20:a1 10.100.28.1 Rogers comm. 15/05/2007 | 00:16:76:21:b0:91 10.100.28.2 Shaheer khan 15/05/2007 | 4c:00:10:60:cd:2e 10.100.28.3 Imaad 15/05/2007 | 00:08:02:d3:4a:ef 10.100.28.4 Hassan 15/05/2007 | 00:09:6b:38:91:0b 10.100.28.5 Hamza bakaiy 15/05/2007 | 00:c0:26:78:06:61 10.100.28.6 Farhan fahim 15/05/2007 | 17/05/2007 | 00:50:04:d6:fc:95 10.100.28.7 Aamir 15/05/2007 | i want this file to be display in tabular form i mean in table.each must be in diffrent column im sure you guys get point what i mean. Regards Net_Spy Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/#findComment-263231 Share on other sites More sharing options...
AndyB Posted May 30, 2007 Share Posted May 30, 2007 fwrite($fh, "$mac $ip $user $adate $bdate |\n"); That implies that a space is the delimiter between data in each line. If so, you can simply explode that line into separate array elements: <?php echo "<tr>"; $parts = explode(" ", $line[0]); for ($x=0;$x<count($parts);$x++) { echo "<td>". $parts[$x]. "</td>"; } echo "</tr>\n"; ?>[code] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/#findComment-264449 Share on other sites More sharing options...
phpgru Posted May 30, 2007 Author Share Posted May 30, 2007 thankz AndyB for your reply.. but i could get your point cause im noob in php .i could not figure out where to modify and add these lines to be honest.im sure it will resovle my issue and display the output in tabular form being within same page i can add info and at the same time it will be displaying the result below in tabular. Regards Net_Spy Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/#findComment-264507 Share on other sites More sharing options...
AndyB Posted May 30, 2007 Share Posted May 30, 2007 In your code, change $fh = fopen('ATT00012.txt','rb'); for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) { $line = trim($line); $info = explode('|', $line); print '' . $info[0] . "<br><br>"; } fclose($fh); to: echo "<table>": $fh = fopen('ATT00012.txt','rb'); for ($line = fgets($fh); ! feof($fh); $line = fgets($fh)) { $line = trim($line); $info = explode('|', $line); echo "<tr>"; $parts = explode(" ", $info[0]); for ($x=0;$x<count($parts);$x++) { echo "<td>". $parts[$x]. "</td>"; } echo "</tr>\n"; } fclose($fh); echo "</table>"; Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/#findComment-264575 Share on other sites More sharing options...
phpgru Posted June 1, 2007 Author Share Posted June 1, 2007 thanks for your response well i did as you said to me but im getting this error message afte modification Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\test\test.php on line 75 im looking for your kind response. Regards Net_Spy Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/#findComment-266163 Share on other sites More sharing options...
phpgru Posted June 2, 2007 Author Share Posted June 2, 2007 Greetings well ive found the error and correct it but still the formate is unmanaged it is not in tabular form.looking forward for your kind repsonse. regards Net_Spy Quote Link to comment https://forums.phpfreaks.com/topic/53268-how-to-formate-the-out-of-file-in-tabular/#findComment-266789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.