Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

echo the columns individually

the foreach command echos all the columns.


tried to echo
$one_row['city']
$one_row['city'] []
and no output

how can i echo the columns individually
if ( empty($_POST['status']) || $_POST['status'] == 'approved' || $_POST['status'] == 'tapproved')
{
  $query = "SELECT * FROM ".cms_db_prefix()."module_compdir_companies";
  $fquery = 'SELECT A.id,A.name,B.value FROM '.cms_db_prefix().'module_compdir_fielddefs A LEFT JOIN '.cms_db_prefix().'module_compdir_fieldvals B ON A.id = B.fielddef_id WHERE B.company_id = ?';

  $dbresult = $db->Execute($query);
  $csv_output = '';
  $delim = '|';
  $csv_lines = array();
  $option_type = array();
  $option_size = array();
  $i = 0;
  while($dbresult && $row=$dbresult->FetchRow())
  {  
    if ($_POST['master'] == 'true')
    {
      $members = array(array( 'userid' => $feusers->GetUserID($row['contact_email'] ) ));
    }
    else
    {
      $members = $feusers->GetUsersByProperties('company_id',$row['id']);
    }
    $categories = $db->GetArray("SELECT category_id FROM ".cms_db_prefix()."module_compdir_company_categories WHERE company_id = ?",array($row['id']));
    $cat_names = array();
    foreach($categories as $onecat)
    {
      switch ($onecat['category_id'])
      {
        case ('1'):  $cat_names[] = "Agency";     break;
        case ('2'):  $cat_names[] = "Consultant";    break;
        case ('3'):  $cat_names[] = "Service Provider";  break;
        case ('4'):  $cat_names[] = "TrainingClients";   break;
        case ('5'):  $cat_names[] = "Conference";   break;
      }
    }
    $company_type = implode(', ', $cat_names);
    if (!empty($company_type) ) $option_type[str_replace(array(',',' '),'', $company_type)] = $company_type;
    if(!empty($_POST['type']) && str_replace(array(',',' '),'', $company_type) != $_POST['type'] )  continue;
    $tmp1 = $db->GetArray($fquery,array($row['id']));
    $company_fields = $comp_dir->array_to_hash( $tmp1, 'name' );
    
    if (!empty($company_fields['Size office']['value']) ) $option_size[str_replace(array(',',' ','-'),'', $company_fields['Size office']['value'])] = $company_fields['Size office']['value'];
    if(!empty($_POST['size']) && str_replace(array(',',' ','-'),'', $company_fields['Size office']['value']) != $_POST['size'] )  continue;

    if ($_POST['payment'] == 'check'  ) continue;
    if ($_POST['payment'] == 'cc' && $company_fields['Amount Charged']['value'] == 'manually' ) continue;


    foreach($members as $onemember)
    {
      if ($_POST['status'] == 'approved' && $feusers->MemberOfGroup($onemember['userid'], '27') ) continue;
      if ($_POST['status'] == 'tapproved' && !$feusers->MemberOfGroup($onemember['userid'], '27')  ) continue;

      $user = $feusers->GetUserInfo($onemember['userid']);
      if( !empty($_POST['expiration']) )
      {
        if( strtotime($user[1]['expires']) < $from  || strtotime($user[1]['expires']) > $to ) continue;
      }
      if ($_POST['master'] == 'false' && strtoupper(trim($row['contact_email'])) == strtoupper(trim($user[1]['username']))) continue;

        //if ( $feusers->IsAccountExpired($onemember['userid']) ) continue;
      if ( isset($csv_lines[$onemember['userid']]) ) $csv_lines[$onemember['userid']] = array();

      $properties = $feusers->GetUserProperties($onemember['userid']);
      $props = $comp_dir->array_to_hash($properties, 'title');
      
      if(!empty($_POST['companyname']) && stripos($row['company_name'], $_POST['companyname']) === false )  continue;
      if(!empty($_POST['firstname']) && stripos($props['first_name']['data'], $_POST['firstname']) === false )  continue;
      if(!empty($_POST['lastname']) && stripos($props['last_name']['data'], $_POST['lastname']) === false )  continue;
      if(!empty($_POST['city']) && stripos($props['city']['data'], $_POST['city']) === false )  continue;

      switch ($company_fields['Payment Method']['value'])
      {
        case 'monthly':
          $new_renewal = mktime(date("H",$company_fields['RenewalDate']['value']),date("i",$company_fields['RenewalDate']['value']),date("s",$company_fields['RenewalDate']['value']),date("n",$company_fields['RenewalDate']['value'])+1,date("j",$company_fields['RenewalDate']['value']),date("Y",$company_fields['RenewalDate']['value']) );
          break;
        case 'quarterly':
          $new_renewal = mktime(date("H",$company_fields['RenewalDate']['value']),date("i",$company_fields['RenewalDate']['value']),date("s",$company_fields['RenewalDate']['value']),date("n",$company_fields['RenewalDate']['value'])+3,date("j",$company_fields['RenewalDate']['value']),date("Y",$company_fields['RenewalDate']['value']) );
          break;
        case 'annually':
        case 'check':
          $new_renewal = mktime(date("H",$company_fields['RenewalDate']['value']),date("i",$company_fields['RenewalDate']['value']),date("s",$company_fields['RenewalDate']['value']),date("n",$company_fields['RenewalDate']['value']),date("j",$company_fields['RenewalDate']['value']),date("Y",$company_fields['RenewalDate']['value'])+1 );
          break;
      }

      $csv_lines[$onemember['userid']][] = $onemember['userid'];
      $csv_lines[$onemember['userid']][] = $user[1]['username'];
      $csv_lines[$onemember['userid']][] = $row['company_name'];
      $csv_lines[$onemember['userid']][] =  $props['phone']['data'];
      $csv_lines[$onemember['userid']][] =  $props['last_name']['data'];
      $csv_lines[$onemember['userid']][] = $props['first_name']['data'];
      //$csv_lines[$onemember['userid']][] = $row['address'];
      $csv_lines[$onemember['userid']][] = $company_fields['Company City']['value'];
      $csv_lines[$onemember['userid']][] = $company_fields['Company State']['value'];
      //$csv_lines[$onemember['userid']][] = $company_fields['Country']['value'];
      //$csv_lines[$onemember['userid']][] = $company_fields['Zip']['value'];
      (strtoupper(trim($row['contact_email'])) == strtoupper(trim($user[1]['username'])))?$csv_lines[$onemember['userid']][] ='Master':$csv_lines[$onemember['userid']][] = '';
      ($feusers->MemberOfGroup($onemember['userid'], '27') )?$csv_lines[$onemember['userid']][] ='T Approved':$csv_lines[$onemember['userid']][] = 'A Approved';
      //$csv_lines[$onemember['userid']][] = $props['title_input']['data'];
      //$csv_lines[$onemember['userid']][] = $props['phone']['data'];
      $csv_lines[$onemember['userid']][] = strftime('%F',strtotime($user[1]['expires']));
      $csv_lines[$onemember['userid']][] = $company_fields['Payment Method']['value'];
      $csv_lines[$onemember['userid']][] = $company_fields['Amount Charged']['value'];
      $csv_lines[$onemember['userid']][] = '';  //$company_fields['ExpireNotify']['value'];
      //$csv_lines[$onemember['userid']][] = $company_fields['Sub_Card']['value'];
      $csv_lines[$onemember['userid']][] = (empty($new_renewal))?'':strftime('%F',$new_renewal );
      $csv_lines[$onemember['userid']][] = strftime('%F',strtotime($user[1]['createdate']));
      $csv_lines[$onemember['userid']][] = $company_fields['Size office']['value'];
      $csv_lines[$onemember['userid']][] = $company_type;

    }
    
  }
}
if ( (empty($_POST['status']) || !($_POST['status'] == 'approved' || $_POST['status'] == 'tapproved') )  && (empty($_POST['type']) || $_POST['type'] == 'Agency') )
{
  $pending_users = $feusers->GetFullUsersInGroup('6');
  foreach($pending_users as $userid => $one_user)
  {
    if ($_POST['payment'] == 'check'  ) continue;
    if ( ($_POST['status'] == 'started' ||  $_POST['status'] == 'tstarted') && !$feusers->MemberOfGroup($userid, '15') ) continue;
    if ( ($_POST['status'] == 'billing' ||  $_POST['status'] == 'tbilling') && $feusers->MemberOfGroup($userid, '15') ) continue;
    if ( ($_POST['status'] == 'billing' ||  $_POST['status'] == 'started') &&  $feusers->MemberOfGroup($userid, '27') ) continue;
    if ( ($_POST['status'] == 'tbilling' ||  $_POST['status'] == 'tstarted')&&  !$feusers->MemberOfGroup($userid, '27') ) continue;

    if ($_POST['master'] == 'false' && ($feusers->MemberOfGroup($userid, '3') ||  $feusers->MemberOfGroup($userid, '27')) ) continue;
    if ($_POST['master'] == 'true' && !($feusers->MemberOfGroup($userid, '3') ||  $feusers->MemberOfGroup($userid, '27')) ) continue;
    if( !empty($_POST['expiration']) )
    {
      if( strtotime($one_user['expires']) < $from  || strtotime($one_user['expires']) > $to ) continue;  
      
    }
    $props = $comp_dir->array_to_hash($one_user['props'], 'title');
    if(!empty($_POST['companyname']) && stripos($props['Company_Name']['data'], $_POST['companyname']) === false )  continue;
    if(!empty($_POST['firstname']) && stripos($props['first_name']['data'], $_POST['firstname']) === false )  continue;
    if(!empty($_POST['lastname']) && stripos($props['last_name']['data'], $_POST['lastname']) === false )  continue;
    if(!empty($_POST['city']) && stripos($props['city']['data'], $_POST['city']) === false )  continue;

    if(!empty($_POST['size']) && str_replace(array(',',' ','-'),'', $props['Agency_Size_Office']['data']) != $_POST['size'] )  continue;

    if ( isset($csv_lines[$userid]) ) $csv_lines[$userid] = array();
    
    $csv_lines[$userid][] = $userid;
    $csv_lines[$userid][] = $one_user['username'];
    $csv_lines[$userid][] = $props['Company_Name']['data'];
    $csv_lines[$userid][] =  $props['phone']['data'];
    $csv_lines[$userid][] =  $props['last_name']['data'];
    $csv_lines[$userid][]= $props['first_name']['data'];
    $csv_lines[$userid][] = $props['city']['data'];
    $csv_lines[$userid][] = $props['state']['data'];
    ($feusers->MemberOfGroup($userid, '3') ||  $feusers->MemberOfGroup($userid, '27'))?$csv_lines[$userid][]='Master':$csv_lines[$userid][] = '';
    ($feusers->MemberOfGroup($userid, '27') )?$type ='T ':$type = 'A ';
    ($feusers->MemberOfGroup($userid, '15') )?$csv_lines[$userid][]=$type.'Started':$csv_lines[$userid][]=$type.'Billing';
    $csv_lines[$userid][] = strftime('%F',strtotime($one_user['expires']));
    $csv_lines[$userid][] = $props['payment_term']['data'];
    $csv_lines[$userid][] = $props['amount_charged']['data'];
    $csv_lines[$userid][]= '';  
    $csv_lines[$userid][] = '';
    $csv_lines[$userid][] = strftime('%F',strtotime($one_user['createdate']));
    $csv_lines[$userid][] = $props['Agency_Size_Office']['data'];
    $csv_lines[$userid][] = 'Agency';
  }
}
  
$csv_header = array("UserID","Email Address","Company","Work Phone","Last Name","First Name","City","State","Master","Status","Member Expiration","Payment Method","Billing Amount","CC Expiry","Check Due","Member Since","Office Size","Company Type");
  

if ($_GET['showtemplate'] != 'false')
{
  echo $feusers->ProcessTemplateFromData('{JQueryTools action=incjs exclude="fancybox,form,lightbox"}');
  echo '<script type="text/javascript">jQuery(document).ready(function($) { jQuery(".cms_sortable").tablesorter({widthFixed: true, widgets: ["zebra"]}); });</script>';

  if ($download)
  {
//    echo '<center><a href="'.$_SERVER['SCRIPT_URI'].'?showtemplate=false" style="text-decoration:none;"><button type="button">Download File</button></a></center>';
  }

  echo '<table class="cms_sortable tablesorter" BORDER=1 CELLPADDING=3><thead><tr><th style="color:#ffffff;">'.implode('</th><th style="color:#ffffff;">', $csv_header).'</th></tr></thead><tbody>';
  foreach($csv_lines as  $one_row)
  {
      $i++;
    echo '<tr><td NOWRAP>'.implode('</td><td NOWRAP>', $one_row).'</td></tr>';
  }

Open in new window

0
rgb192
Asked:
rgb192
2 Solutions
 
HellmarkCommented:
If you wish to maintain a table like appearance, you cannot "echo the columns". Echo generates one line at a time, and with HTML, as well as building a table in plain text, you have to print by rows.

If you mean you want to gather only the data from one portion of the database, such as the User ID's, then you may want to clarify that. Also, in the future, carefully chosen phrasing will garner more help.

Given the seeming lack of understanding of the given code, I am wagering this is probably part of a programming assignment, and that you did not write the example given. On top of this same exact code being available elsewhere, I would say it is most likely the case. Please note that attempting to have the users here complete your homework assignments is against the terms of service, which can be punishable up to banning. Since you're a paying member, that would not be good to have paid for something that you can no longer use.
0
 
Ray PaseurCommented:
Sigh.  It looks like the $one_row variable is dependent on $csv_lines which is built in the script with data from a lot of places.

Here is what you might want to do after line 180:

echo "<pre>";
var_dump($one_row);
die();

That will enable you to see what is in the $one_row variable.  You will get the first $one_row then the script will terminate.  In the event that you want to see all of the $one_row variables remove die(); from the script.

You might also want to use var_dump() to see the structure and contents of $csv_lines.
0
 
rgb192Author Commented:
Thanks
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now