Current location: Hot Scripts Forums » Programming Languages » PHP » adding to table


adding to table

Reply
  #1 (permalink)  
Old 04-01-08, 01:33 PM
Dangar Dangar is offline
New Member
 
Join Date: Mar 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
adding to table

hi all,
im tryin to continuously add to a table
im not too good at php but here is some code that i have
PHP Code:

<?php
$file 
fopen ("doc.txt"'r');
$textArray = array();
while ( !
feof($file) ) {
    
$textArray[] = fgets($file);
    for ( 
$i $i<count($textArray) ; $i++ ) {
    list(
$name) = explode (":"$textArray[$i]);
    print 
"<td>$name[$i]</td>";
        }
}
?>
i know i am clearly doing something wrong here.
i would like the page to take text from the doc.txt file at every colon ":" and then display it in its own table cells on the page.

so, for instance, if doc.txt contains "how:are:you:doing:" <---without quotes
i would like to display
how
are
you
doing

note that these will all be in their own table cell with using <tr><td></td></tr> tags

any help is much appreciated!

Last edited by Nico; 04-01-08 at 01:57 PM.
Reply With Quote
  #2 (permalink)  
Old 04-01-08, 03:49 PM
phpdoctor's Avatar
phpdoctor phpdoctor is offline
Code Guru
 
Join Date: Feb 2007
Location: New Zealand
Posts: 767
Thanks: 4
Thanked 2 Times in 2 Posts
This should work:

PHP Code:

<?php

$file 
fopen ("doc.txt"'r');
$textArray = array();
while ( !
feof($file) ) 
{
    
$textArray[] = fgets($file);
    
    for ( 
$i $i<count($textArray) ; $i++ ) 
    {
        
$words explode (":"$textArray[$i]);
        foreach (
$words as $word)
        {
            echo 
$word.'<br>' ;
        }
    }
}
?>
You were exploding out the first word and displaying just the first letter...
This code explodes the current line and then loops through each node and echos it.

Lex
__________________
01010000 01001000 01010000
Reply With Quote
  #3 (permalink)  
Old 04-01-08, 10:20 PM
Dangar Dangar is offline
New Member
 
Join Date: Mar 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
wow, this really helps. thanks a lot!
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
MYSQL database countll Database 2 06-19-07 04:20 PM
What do you think of my database structure? Oskare100 Database 5 12-27-06 07:43 AM
Pretty simple ( i think) question any help!?!? 0o0o0 PHP 2 04-07-06 10:47 AM
Adding 2 table row counts together Kokkei Mizu PHP 6 10-16-05 05:34 PM
adding tooltip to an entire table davidklonski HTML/XHTML/XML 2 06-09-04 12:01 AM


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