Current location: Hot Scripts Forums » Programming Languages » PHP » creating tabular column in php files


creating tabular column in php files

Reply
  #1 (permalink)  
Old 06-23-09, 12:15 AM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
creating tabular column in php files

Hi

i have a file into which i keep appending data, i want this data to be put in a table so that there is clarity for the person who sees it. can someone help me out as to how to create tables in files. using html the normal way things don't seem to work.

Please revert back to me incase i am not clear.

Thanks !!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-23-09, 09:16 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
You will need to explain where the file is located,
what kind of data is in the file and how it is arranged,
how you are appending to the file (I am assuming you are you using PHP?)
and how you want the data arranged in the table.
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 06-24-09, 04:35 AM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
ya i am using php to append my file and the file is actually a log file. right now its appended into the file as

username:
id:

i want it in the form of a table as shown below

username id

the thing is that i want to view the log file from my webpage, so i have an option view log file, and that in turn should read the file and put it in a table form and show the user.

i hope this much info should do.

Thanks !!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 06-24-09, 11:40 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Your not clear on how the data is arranged in the file.
Can you please give me an example of how the data actually looks like?
__________________
Jerry Broughton

Last edited by job0107; 06-24-09 at 11:45 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 06-24-09, 11:39 PM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
alright, this is how the code looks like,

Code:
$myfile = "logfile.txt";
$fh = fopen($myfile,'a') or die("can't open file);
fwrite($fh,"Username:" .$name);
fwrite($fh,"ID:" .$id);
fclose($fh);
i hope this would be of help to to you.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 06-25-09, 11:34 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
This is just an example.
I am sure you can modify it to suit your needs.

Please note: I have modified the way the data is stored in the file, so you will either want to empty or delete the file if it already exists.
PHP Code:

<?php
$myfile 
"logfile.txt";
$username = array();
$id = array();
$sw 0;
$msg "<span style='font-size:20px;'>Enter a Username and ID.</span>";
if(
file_exists($myfile))
{
 
$fh fopen($myfile,'r');
 while(!
feof($fh))
 {
  
$temp_username trim(fgets($fh));
  
$temp_id trim(fgets($fh));
  if(!empty(
$_POST["username"]))
  {
   if(
$temp_username == $_POST["username"])
   {
    
$sw 1;
    
$msg "<span style='font-size:20px;color:#f00;'>User already exists.</span>";
    }
   }
  
$username[] = $temp_username;
  
$id[] = $temp_id;
  }
 
fclose($fh);
 }
if(empty(
$sw))
{
 if(
$_POST["username"] && $_POST["id"])
 {
  
$fh fopen($myfile,'a') or die("can't open file");
  
fwrite($fh,$_POST["username"]."\r\n");
  
$username[] = $_POST["username"];
  
fwrite($fh,$_POST["id"]."\r\n");
  
$id[] = $_POST["id"];
  
fclose($fh);
  
$_POST["username"] = "";
  
$_POST["id"] = "";
  
$msg "<span style='font-size:20px;color:#00f;'>New user added.</span>";
  }
 }
if(!empty(
$username))
{
 echo 
"<table border='1'><tr><th>Username</th><th>ID</th></tr>";
 for(
$i=0;$i<count($username);$i++)
 {
  if(!empty(
$username[$i])){echo "<tr><td>".$username[$i]."</td><td>".$id[$i]."</td></tr>";}
  }
 echo 
"</table><br /><div style='border:1px solid #000;width:237px;padding:5px;'><div style='border:1px solid #000;width:225px;text-align:center;margin-bottom:10px;'>$msg</div>";
 }
?>
<form action="#" method="post" style="margin:0px;">
<table>
 <tr><td>Username: </td><td><input type="text" name="username" value="<?php echo $_POST["username"]; ?>"></td></tr>
 <tr><td align="right">ID: </td><td><input type="text" name="id" value="<?php echo $_POST["id"]; ?>"></td></tr>
 <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td></tr>
 </table>
</form>
</div>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 06-30-09, 03:07 AM
reshma reshma is offline
Newbie Coder
 
Join Date: Mar 2009
Posts: 38
Thanks: 0
Thanked 2 Times in 2 Posts
Thanks a lot !!!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] it works on localhost but not on hosting account? myslowquietlife PHP 42 12-19-08 10:31 AM
virus in php files umarrana PHP 2 11-05-08 07:51 PM
php download script for files hosted on remote server SlaveDriver Script Requests 0 09-12-08 11:08 AM
PHP extracting rar files. scott2500uk PHP 5 03-04-08 03:26 AM
Creating directories and files cobalto2060 PHP 1 08-17-03 04:20 PM


All times are GMT -5. The time now is 07:41 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.