I have a text file that contains 3 values seperated by | on each line...
member|address|city
I currently have them being sorted in 2 columns...
but it displays them from left to right and then down
aa ab
ac ad
ba bb
bc bd
I need it to go from top to bottom then then left to right
like...
aa ba
ab bb
ac bc
ad bd
in the same 2 columns...
Im pulling out my hair as this seems simple.. but ive screwed it up twice...
Here is my working code.. can someone please help me modifiy it or does nayone have a better solution?
<?
//you need this - it tells the data what collumn to go to
$count = 1;
$column = 1;
//db connect and select
$filename = 'websuppliers.txt';
$fp = fopen( $filename, 'r' );
$file_contents = fread( $fp, filesize( $filename ) );
fclose( $fp );
$lines = explode ( "\n", $file_contents );
print("<table width=500>");
print("<tr><td>");
//loop statement
foreach ($lines as $line) {
list( $member, $city, $state ) = explode( '|', $line );
$member = trim($member);
$city = trim($city);
$state = trim($state);
$linecount=count(file("$filename"));
$halfcount=$linecount/2;
$currentcount=0;
// this is the column 1
if ($column == 1)
{
print("
<table width=\"250\" border=\"1\" cellspacing=\"1\" cellpadding=\"2\" bordercolor=\"#000000\" align=\"center\">
<tr>
<td>
<table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td bgcolor=\"#ffffff\"><font color=\"#993300\" face=\"Verdana\" size=\"1\"><b>$member  </b></font></td>
</tr>
</table>
</td>
</tr>
</table>
");
}
print("</td><td>");
if($column != 1)
{
//this is the column 2
print("
<table width=\"250\" border=\"1\" cellspacing=\"1\" cellpadding=\"2\" bordercolor=\"#000000\" align=\"center\">
<tr>
<td>
<table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td bgcolor=\"#ffffff\"><font color=\"#993300\" face=\"Verdana\" size=\"1\"><b>$member  </b></font></td>
</tr>
</table>
</td>
</tr>
</table>
");
}
//increment the count
$count += 1;
// this is a modulus operator it gets the remainder of the equation
$column = $count % 2;
if($currentcount <= $halfcount) { $column == 1; } else { $column == 2; }
}
print("</td></tr>");
print("</table>");
?>