Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Formatting an Array to a table.

    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 Code:
    <?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.

  • #2
    New Coder
    Join Date
    Jan 2008
    Posts
    63
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I think that last section should be something more like :

    Code:
    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";
    }
    Web hosting by coders, for coders: php hosting - Magento eCommerce hosting - perl hosting - check us out!

  • #3
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Sweet thanks, I woulda never thought of that on my own XD


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •