php multidimensional array to html table

  • damien41630
  • Born
  • Born
  • damien41630
  • Posts: 4

Post 3+ Months Ago

I am attempting to take my array and output it into a table. Below is the code generating the array.

Code: [ Select ]
$rows = mssql_num_rows($ret_info);
    if($rows){    
        for($i=0;$i<$rows;$i++){
            $disdate = mssql_result($ret_info,$i,1);
            $producttype=mssql_result($ret_info,$i,3);
            $phone = mssql_result($ret_info,$i,0);
            $contractdate= mssql_result($ret_info,$i,5);
            $svcdesc= mssql_result($ret_info,$i,2);
                
            //format date then subtract dates to determine renewal status
            $fcontractdate = date('m-d-Y', strtotime($contractdate));
            $datediff=dateDiff("-", $fcontractdate, $date);
            
            //determine renewal status
            if ($datediff<31){
            $contract[$i]['Cell Number']="$phone";
            $contract[$i]['Contract Date']="$contractdate";
            $contract[$i]['Renew']=ccbutton(Renew, $action="Renew");
        } else {
            $contract[$i]['Cell Number']="$phone";
            $contract[$i]['Contract Date']="$contractdate";
  1. $rows = mssql_num_rows($ret_info);
  2.     if($rows){    
  3.         for($i=0;$i<$rows;$i++){
  4.             $disdate = mssql_result($ret_info,$i,1);
  5.             $producttype=mssql_result($ret_info,$i,3);
  6.             $phone = mssql_result($ret_info,$i,0);
  7.             $contractdate= mssql_result($ret_info,$i,5);
  8.             $svcdesc= mssql_result($ret_info,$i,2);
  9.                 
  10.             //format date then subtract dates to determine renewal status
  11.             $fcontractdate = date('m-d-Y', strtotime($contractdate));
  12.             $datediff=dateDiff("-", $fcontractdate, $date);
  13.             
  14.             //determine renewal status
  15.             if ($datediff<31){
  16.             $contract[$i]['Cell Number']="$phone";
  17.             $contract[$i]['Contract Date']="$contractdate";
  18.             $contract[$i]['Renew']=ccbutton(Renew, $action="Renew");
  19.         } else {
  20.             $contract[$i]['Cell Number']="$phone";
  21.             $contract[$i]['Contract Date']="$contractdate";


Here are the results of the array.
[contract] => Array
(
[0] => Array
(
[Cell Number] => 6067412588
[Contract Date] => Apr 23 2010 12:00AM
)

[1] => Array
(
[Cell Number] => 6067921155
[Contract Date] => Feb 27 2010 12:00AM
)

[2] => Array
(
[Cell Number] => 6067910012
[Contract Date] => Nov 15 2009 12:00AM
[Renew] =>

I want the table to look something like this:
Quote:
Cell Number Contract Date Renew
6067910012 Nov 15 2009 12:00AM Renew button
6067921155 Feb 27 2010 12:00AM
6067921155 Feb 27 2010 12:00AM


Any help would be great, thanks
Moderator Remark: added [code] tags
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Try the following:
PHP Code: [ Select ]
<pre><?php
$array = array('contract' => Array (
      '0' => Array (
      'Cell Number' => 6067412588,
      'Contract Date' => 'Apr 23 2010 12:00AM',
   ),
      '1' => Array (
      'Cell Number' => 6067921155,
      'Contract Date' => 'Feb 27 2010 12:00AM',
   ),
      '2' => Array (
      'Cell Number' => 6067910012,
      'Contract Date' => 'Nov 15 2009 12:00AM',
      'Renew' => null
   )
));
 
echo '
<table>
   <tr>
      <td>
         Cell Number
      </td>
      <td>
         Contract Date
      </td>
      <td>
         Renew
      </td>
   </tr>
';
for($i = 0; $i < sizeof($array['contract']); ++$i)
{
   echo '  <tr>
';
   foreach($array['contract'][$i] as $value)
   {
      if($value != false)
      {
         echo '    <td>
         ', $value, '
      </td>
';
      }
   }
   echo '    <td>
         <input type="button" name="renew" value="Renew" />
      </td>
   </tr>
';
}
echo '</table>
';
 
print_r($array);
?></pre>
  1. <pre><?php
  2. $array = array('contract' => Array (
  3.       '0' => Array (
  4.       'Cell Number' => 6067412588,
  5.       'Contract Date' => 'Apr 23 2010 12:00AM',
  6.    ),
  7.       '1' => Array (
  8.       'Cell Number' => 6067921155,
  9.       'Contract Date' => 'Feb 27 2010 12:00AM',
  10.    ),
  11.       '2' => Array (
  12.       'Cell Number' => 6067910012,
  13.       'Contract Date' => 'Nov 15 2009 12:00AM',
  14.       'Renew' => null
  15.    )
  16. ));
  17.  
  18. echo '
  19. <table>
  20.    <tr>
  21.       <td>
  22.          Cell Number
  23.       </td>
  24.       <td>
  25.          Contract Date
  26.       </td>
  27.       <td>
  28.          Renew
  29.       </td>
  30.    </tr>
  31. ';
  32. for($i = 0; $i < sizeof($array['contract']); ++$i)
  33. {
  34.    echo '  <tr>
  35. ';
  36.    foreach($array['contract'][$i] as $value)
  37.    {
  38.       if($value != false)
  39.       {
  40.          echo '    <td>
  41.          ', $value, '
  42.       </td>
  43. ';
  44.       }
  45.    }
  46.    echo '    <td>
  47.          <input type="button" name="renew" value="Renew" />
  48.       </td>
  49.    </tr>
  50. ';
  51. }
  52. echo '</table>
  53. ';
  54.  
  55. print_r($array);
  56. ?></pre>
  • damien41630
  • Born
  • Born
  • damien41630
  • Posts: 4

Post 3+ Months Ago

Thanks

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 179 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.