...

View Full Version : Formatting an Array to a table.



kJasso
07-25-2008, 01:13 AM
I've been working on this script for a while and so far its not working the way I need. It uses 3 static locations (not listed in a database) and I need to put each of those in a row with 7 columns after. So it would look something like this:

|Location | Number(A) | Number (B) | Number (C) | Number (D) | Number (E) | Number (F) | Number (G) |

So my orginal thought was to put it into an array where it would list location 1, then all the values that go with it and so on to the next location. This is what I had:



<?php
//connect to the server and select database
$conn = mysql_connect("****", "****", "****")
or die(mysql_error());
mysql_select_db("****",$conn) or die(mysql_error());

//Gather Information
$get_topics = "SELECT master_id, docnum, entry_create_time, sdate, f_name, l_name, opncls FROM ****";
$get_accounts = "SELECT master_id, post_create_time, entrydate, loc, doctype, bbalance, balance, fiscalyr FROM ****";

$get_topics_res = mysql_query($get_topics,$conn) or die(mysql_error());
$get_accounts_res = mysql_query($get_accounts,$conn) or die(mysql_error());

while (($entry_info = mysql_fetch_array($get_topics_res)) && ($loc_info = mysql_fetch_array($get_accounts_res))) {
$master_id = $entry_info['master_id'];
$docnum = stripslashes($entry_info['docnum']);
$loc = stripslashes($loc_info['loc']);
$entry_create_time = $entry_info['entry_create_time'];
$opncls = stripslashes($entry_info['opncls']);
//$fiscal = $loc_info['fiscalyr'];

//Post Fiscal Year
//$fisyr = $_POST['x'];


//Count number of accounts
if ($fiscal != $fisyr) {
} else if ($loc == "Department of Revenue") {
$depart++;
} else if ($loc == "ORPD") {
$orpd++;
} else if ($loc == "Collections") {
$col++;
} else {
echo "& Die";
}

//Count Number of Closed Accounts
if ($fiscal != $fisyr) {
} else if ($loc == "Department of Revenue") {
if ($opncls == "Closed") {
$dclo++;
}
} else if ($loc == "ORPD") {
if ($opncls == "Closed") {
$orpdclo++;
}
} else if ($loc == "Collections") {
if ($opncls == "Closed") {
$cclo++;
}
}

$accounts_array = array(
array("Location A", "$depart", "$dclo", "colph", "woph", "adjph", "revph", "balph"),
array("Location B", "$orpd", "$oclo", "colph", "woph", "adjph", "revph", "balph"),
array("Location C", "$col", "$cclo", "colph", "woph", "adjph", "revph", "balph")
);
foreach ($accounts_array as $a_a) {
while (list($l, $n, $c, $cl, $w, $a, $r, $b) = each ($a_a)) {
$display_accounts .="
<tr>
<td>$l</td>
<td>$n</td>
<td>$c</td>
<td>$cl</td>
<td>$w</td>
<td>$a</td>
<td>$r</td>
<td>$b</td>
</tr>";
}
}

//Close Table
$display_accounts .="</table>";


}

?>


And it makes the table go insane.

awatson
07-25-2008, 05:34 PM
I think that last section should be something more like :



foreach ($accounts_array as $a_a) {
$display_accounts .= "<tr>\n";
foreach ($a_a as $fld) {
$display_accounts .= "\t<td>$fld</td>\n";
}
$display_accounts .= "</tr>\n";
}

kJasso
07-25-2008, 06:32 PM
Sweet thanks, I woulda never thought of that on my own XD



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum