Elvis L Posted July 17, 2014 Report Share Posted July 17, 2014 Sveiki, skripts diezgan primitīvs, bet pēc idejas vairāk arī neko nevajag, lieta tāda, ka izveidojot tabulu, viņš nolasa tikai pirmo rindu, kur varētu būt problēma? <head> <link rel="stylesheet" type="text/css" href="stils.css"> </head> <?php $fails="data.txt"; $open=fopen($fails, 'r'); $text=fgets($open, filesize($fails)); $saturs=explode(" | ", $text); ?> <?php $fi = file("data.txt"); $rinduskaits = count($fi); for ($i=0;$i<$rinduskaits;$i++) { $rinda = chop($fi[$i]); } ?> <div class="CSSTableGenerator" > <table> <tr> <td> ID </td> <td > Name </td> <td> Email </td> <td> Proc </td> <td> RAM </td> <td> HDD </td> <td> Office </td> <td> Antivirus </td> <td> Tilde </td> <td> Username </td> <td> Password </td> <td> IP </td> <td> Domain </td> <td> DVD </td> </tr> <tr> <td > <?php echo $saturs['0'] ?> </td> <td> <?php echo $saturs['1'] ?> </td> <td> <?php echo $saturs['2'] ?> </td> <td> <?php echo $saturs['3'] ?> </td> <td> <?php echo $saturs['4'] ?> </td> <td> <?php echo $saturs['5'] ?> </td> <td> <?php echo $saturs['6'] ?> </td> <td> <?php echo $saturs['7'] ?> </td> <td> <?php echo $saturs['8'] ?> </td> <td> <?php echo $saturs['9'] ?> </td> <td> <?php echo $saturs['10'] ?> </td> <td> <?php echo $saturs['11'] ?> </td> <td> <?php echo $saturs['12'] ?> </td> <td> <?php echo $saturs['13'] ?> </td> </tr> </table> </div> <BR /> <a href="/reck/xls.php">Download xls</a> Quote Link to comment Share on other sites More sharing options...
Kavacky Posted July 17, 2014 Report Share Posted July 17, 2014 Jo tur tu statiski esi uzrakstījis, ka tikai viena rinda ir, kuru aizpilda ar kaut kādiem datiem. Tu esi gribējis pa vienai lasīt visas rindas un tad parādīt, bet tas cikls sākas un uzreiz arī beidzas, pirms tu sāc kaut ko drukāt: for ($i=0;$i<$rinduskaits;$i++) { $rinda = chop($fi[$i]); }To ciklu būtu jāliek pēc pirmās tabulas rindas ar kolonnu nosaukumiem un tad jāvada ārā "echo $rinda[<X>]". Quote Link to comment Share on other sites More sharing options...
Elvis L Posted July 17, 2014 Author Report Share Posted July 17, 2014 Vai tu nevarētu parādīt uzskatāmāku piemēru, tiko mēģināju mainīt vietām tabulas, rezūltāts nekāds Quote Link to comment Share on other sites More sharing options...
zeCode Posted July 17, 2014 Report Share Posted July 17, 2014 <!DOCTYPE html> <html> <head> <title>Megatest</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="stils.css"> </head> <body> <div class="CSSTableGenerator" > <?php /** function special 4 u **/ function myUberCoolTable($row, $run_time = 0, $elem_sep = ' | '){ $html = ''; $table_elements = array( 0 => 'ID' ,1 => 'Name' ,2 => 'Email' ,3 => 'Proc' ,4 => 'RAM' ,5 => 'HDD' ,6 => 'Office' ,7 => 'Antivirus' ,8 => 'Tilde' ,9 => 'Username' ,10 => 'Password' ,11 => 'IP' ,12 => 'Domain' ,13 => 'DVD' ); $data = ($row) ? explode($elem_sep, $row) : false; $tab = chr(9); $nl = "\n"; foreach($table_elements as $key => $value){ $html .= $nl.$tab.$tab.( ( $run_time == 0) ? '<td>'.$value.'</td>' : '<td>'.(isset($data[$key]) ? trim($data[$key]) : '').'</td>' ); } return $nl.$tab."<tr>".$html.$nl.$tab."</tr>"; } $table_html = myUberCoolTable(false, 0); $file = 'data.txt'; $handle = fopen($file, "r"); $i = 1 ; while (($buffer = fgets($handle, filesize($file))) !== false) { $table_html .= myUberCoolTable($buffer,$i); $i++; } echo ($table_html) ? '<table>'.$table_html."\n".'</table>' : 'No data'; ?> </div> <br /> <a href='/reck/xls.php'>Download xls</a> </body> </html> Quote Link to comment Share on other sites More sharing options...
jurchiks Posted July 17, 2014 Report Share Posted July 17, 2014 (edited) Kā cilvēkiem patīk sarežģīt pašiem sev dzīvi... <table> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Proc</th> <th>RAM</th> <th>HDD</th> <th>Office</th> <th>Antivirus</th> <th>Tilde</th> <th>Username</th> <th>Password</th> <th>IP</th> <th>Domain</th> <th>DVD</th> </tr> <?php $data = file_get_contents('data.txt'); $lines = explode("\n", $data); foreach ($lines as $line) { $data = explode(' | ', trim($line)); echo '<tr>', '<td>', $data[0], '</td>', '<td>', $data[1], '</td>', '<td>', $data[2], '</td>', '<td>', $data[3], '</td>', '<td>', $data[4], '</td>', '<td>', $data[5], '</td>', '<td>', $data[6], '</td>', '<td>', $data[7], '</td>', '<td>', $data[8], '</td>', '<td>', $data[9], '</td>', '<td>', $data[10], '</td>', '<td>', $data[11], '</td>', '<td>', $data[12], '</td>', '<td>', $data[13], '</td>', '</tr>'; } ?> </table> Edited July 17, 2014 by jurchiks Quote Link to comment Share on other sites More sharing options...
zeCode Posted July 17, 2014 Report Share Posted July 17, 2014 Kā cilvēkiem patīk sarežģīt pašiem sev dzīvi... Triviāli, piemērs tev labāks, bet jautājums kuru kodu labāk izmantot, pielāgot ja nav tikai 1 fails bet 10 dažādi ( teiksim ja visu glabā ne DB - produkti, pirkumi, atlaides... ) ? Tā pat noderētu foreach pie izvades (vairāk par 3 rindām). Kods tev tīrāks un vieglāk uztverams! Galvenais ir tikai jautājums - cik faili un vai to dati var atškirās, un tad man liekas ka tu arī izmantotu funciju vai klasi, kods jau arī būs jautur kādam - pie normāla projekta dzīvescikla! Quote Link to comment Share on other sites More sharing options...
jurchiks Posted July 17, 2014 Report Share Posted July 17, 2014 Nav absolūti nekāda problēma pielāgot, bet tavs kods ir daudz par sarežģītu tik vienkāršai problēmai. OP prasīja par izvadi no viena faila. That's all there is to it. Quote Link to comment 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.