SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php table script

    I would like to use a text file to contain the content for a table. i would like it to take my content and place it in cell. how i want to do this is this way (heres an example of the text file):

    Item 1|Item 2|Item 3|Item 4
    Item 5|Item 6|Item 7|Item 8
    Item 9|Item 10|Item 11|Item 12
    Item 13|Item 14|Item 15|Item 16


    that would make a 4 collumn, 4 row table different rows mean different rows of the table and each collumn is seperated by a |

    Oh yeah... i forgot, i would like each row to alternate colors.

    can it be done?

    you understand?
    Ok I'm too tired from work to think. if you have any ideas let me know.

  2. #2
    ********* wombat firepages's Avatar
    Join Date
    Jul 2000
    Location
    Perth Australia
    Posts
    1,717
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are probably countless ways - this is just one of them....

    PHP Code:
    <?php
    $file
    =file("test.txt");
      while(list(
    $key,$var)=each($file))
        {
        if(
    $c_count==1)
                {
            
    $col="e3e3e3";$c_count=0;
                }else{
                
    $col="f0f0f0";$c_count++;
                }
            
    $thisvar=str_replace("|","</td><td bgcolor=\"$col\">",$var);
            
    $table .="<tr><td bgcolor=\"$col\">$thisvar</td></tr>";
        }
    ?>

    <table cellspacing="0"><tr><?echo $table;?></table>

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is a simple_table function. Please thank Dr_Larry_Pepper, who if I'm not mistaken, gave me the code in the first place

    PHP Code:
    function simple_table($xresults) {
    /*    

        Take any results from a MySQL query and throw them into a simple table
        to give a nice simple display. Comes in really handy for testing 
        results sets to see what you are actually getting back if things
        seem to be broken.
        
        To use set up your query, make it, test it and then send the results 
        to this function like this:
        
        simpletable($your_results_variable_here);
        
        A better way to use it would probably to echo it straight out:
        
        echo ( simpletable($your_results_variable_here) );
    */

        
    $table '<table cellpadding=3 cellspacing=1 border=1><tr>'

        
    $x mysql_num_fields($xresults);
        
    $i 0;


        while (
    $i $x ) {
            
    $meta mysql_fetch_field($xresults);
            
    $table .= '<td><font face=verdana size=2>'.'<b>' $meta->name '</font></td>';
            
    $i++;
        }

        while ( 
    $row mysql_fetch_array($xresults) ) {
           
    $table .= '</tr><tr>';
           for (
    $y 0$y $x$y++) {
               
    $table .= '<td><font face=verdana size=2>' $row[$y] .
    '</font></td>';
           }
       }


        
    $table .= '</tr></table>';
        
        return 
    $table;


  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats all? damn thats easy. thanx dudes!

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by infinitium
    here is a simple_table function. Please thank Dr_Larry_Pepper, who if I'm not mistaken, gave me the code in the first place
    that's not my code. i don't want to get credit for someone else's work.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •