PHP ALIGNMENT

Hi all,

I am reading information from a non-delimited txt file and putting that information, in this example people and grades, onto a webpage using html/php using tables. I have managed to build the tables but the headings do not line up. Have been trying to get this for ages but can’t see what the problem is. Any clues?

Grateful for any and all help.

PHP CODE:

<?php $txt_file = file_get_contents('input.txt'); $rows = explode("\n", $txt_file); array_shift($rows); echo ""; foreach($rows as $row => $data) { //get row data $row_data = explode(' ', $data); $info[$row]['name'] = $row_data[0]; $info[$row]['score'] = $row_data[1]; $info[$row]['result']= $row_data[2]; //display data echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
NAME SCORE GRADE
" . $info[$row]['name'] . "" . $info[$row]['score'] . "" . $info[$row]['result'] . "
" ?>

INPUT.txt

bill 45 Fail
fred 64 Pass
tom 62 Pass
tim 55 Pass
roger 10 Fail
nigel 67 Pass

Edit:

I forgot to put and which means it now it looks like this:

NAME SCORE GRADE
bill 45 Fail
fred 64 Pass
tom 62
tim 55
roger 10 Fail
etc

I also have to drop the input text down a line for it to show Bill.

There you go:
[php]<?php
function bust_rows_open($file, $delim) {
$txt_file = file_get_contents($file);
$rows = explode($delim, $txt_file);
foreach($rows as $row) {
$d[] = array_filter(explode(’ ', $row));
}
$data = array_map(‘array_values’, $d);
for($i=0;$i<sizeof($data);$i++) {
$info[$i][‘name’] = $data[$i][0];
$info[$i][‘score’] = $data[$i][1];
$info[$i][‘result’]= $data[$i][2];
}
return $info;
}
$info = bust_rows_open(‘input.txt’, “\n”);
?>

<?php for($i=0;$i<sizeof($info);$i++) { echo ''; echo ''; echo ''; echo ''; echo ''; } ?>
NAME SCORE GRADE
' . $info[$i]['name'] . '' . $info[$i]['score'] . '' . $info[$i]['result'] . '
[/php]

Hope that helps.

Red :wink:

Superb. Thank you very much, RedScouse ;D

Your welcome :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service