Log in

View Full Version : PHP Array into table



mcanous
05-18-2011, 03:58 PM
I have this code and want to organize it into a suitable table, how can I do this

I have this code that I am confused about, I can get the outpoot into an array but I cannot organize it into a table, please help

<META HTTP-EQUIV="REFRESH" CONTENT="20">
<?php
$xmlUrl = "https://secure.ifbyphone.com/ibp_api.php?api_key=6a9212f2af5a0ee41df847fd59eb63acf219404c&action=report.call_detail&start_date=20110517&end_date=20201231&format=csv&date_added=1&phone_label =1&dnis=1&ani=1&call_duration=1&transfer_to_number=1&call_type_filter=All"; // XML feed file/URL
$xmlStr = file_get_contents($xmlUrl);
$filearray = explode("\n", $xmlStr);
while (list($var, $val) = each($filearray)) {
++$var;
$val = trim($val);
print "Line $var: $val<br />";
$input =
$cols = 5;

echo "<table border=\"5\" cellpadding=\"10\">";

for ($i=0; $i < count($input); $i++)
{
echo "<tr>";
for ($c=0; $c<$cols; $c++)
{
echo "<td>$input[$i]</td>";
}
echo "</tr>";

}

echo "</table>";


}

JoeDaStudd
05-19-2011, 11:47 AM
This line

$xmlUrl = "https://secure.ifbyphone.com/ibp_api.php?api_key=6a9212f2af5a0ee41df847fd59eb63acf219404c&action=report.call_detail&start_date=20110517&end_date=20201231&format=csv&date_added=1&phone_label =1&dnis=1&ani=1&call_duration=1&transfer_to_number=1&call_type_filter=All"; // XML feed file/URL
Should be

$xmlUrl = "https://secure.ifbyphone.com/ibp_api.php?api_key=6a9212f2af5a0ee41df847fd59eb63acf219404c&action=report.call_detail&start_date=20110517&end_date=20201231&format=csv&date_added=1&phone_label=1&dnis=1&ani=1&call_duration=1&transfer_to_number=1&call_type_filter=All"; // XML feed file/URL
There is a space which cuts off half the data.

This line

$input =
Should be

$input = explode(',',$val);

Then its just a case of tweaking the output.

I could rewrite it for you so it works and you just have to copy and paste it, but where's the fun in that :D.