By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,903 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,903 IT Pros & Developers. It's quick & easy.

Multidimensional array declaration and dispaly

P: 8
Hi All,

there are 4 different categories which each month will bw updated. In each category(source),there are many editions. I have to display 6months updates. its like one is month array which contains 6months' names.
source array contains source of that month.
$table_row conatins editions of particular source.

looking forward to get help from anyone
Thanks

Here is the code..
Expand|Select|Wrap|Line Numbers
  1. for($i=$current_month; ($num_displayed_months < 5) && ($i >= 0); $i--) {
  2.     $result_array = array();
  3.     $num_array = array();
  4.     $num_total = 0;
  5.     if($i == 0){
  6.        $i = $current_month;
  7.      $current_year = date("Y",mktime(0,0,0,$current_month,1,$current_year-1));
  8.     }
  9.     $array = array("Reviewes" => "systematic_reviews" , "Summaries" => "evidence_summary" , "Care Bundles" => "care_bundles" , "Best Practice Information Sheets" => "best_practice");
  10.     foreach($array as $source => $source_query) {
  11.  
  12.         $query = "SELECT DISTINCT ID,Title,Authors,Source,Year,Date,pdfURL,htmlURL FROM (\n${$source_query}\n) AS `{$source_query}`\n WHERE Date LIKE '$current_year-%$i-%' ORDER BY Date DESC";
  13.         $result_array[$source] = mysql_query($query, $dblink) or die(mysql_error() );
  14.         $num_array[$source] = mysql_num_rows($result_array[$source]);
  15.     }
  16.  
  17.     foreach ($num_array as $n) {
  18.         $num_total += $n;
  19.     }
  20.  
  21.     if ($num_total == 0) continue;
  22.  
  23.     $name = date("F",mktime(0,0,0,$i));
  24.       $month_text .= "<p><a href ='#$name'>New updates in $name $current_year</a></p>";
  25.       $month_array = array($month_text);
  26.  
  27.     foreach($array as $source => $source_query) {
  28.         $result = $result_array[$source];
  29.         $num = $num_array[$source];
  30.  
  31.         if($num){
  32.          $source_text .= "<p><a href = '#$source'>$source</a></p>";
  33.          $source_array = array($source_text);
  34.  
  35.  
  36.            $table_row = array();
  37.             $table_row[] = "<table class='pretty'>
  38.                 <tr  valign='bottom' class='header'>
  39.                     <th>Id</th>
  40.                     <th><p align='left'>Publication Title</p></th>
  41.                     <th><p align='left'>Source</p></th>
  42.                     <th><p align='left'>Authors</p></th>
  43.                     <th><p align='left'>Year</p></th>
  44.                     <th>Date</th>
  45.                     <th>ViewPDF</th>
  46.                     <th>ViewHTML</th> 
  47.                 </tr> ";
  48.                 $alternate_row = false;
  49.                 while($row = mysql_fetch_assoc($result)){
  50.                     extract($row);
  51.                     //output table
  52.                     $trclass = ($alternate_row == true)? "even" : "odd" ;
  53.                                         $table_row[] = "<tr class = $trclass>";
  54.  
  55.                     $table_row[] = "<td>$ID</td>";
  56.                         $title_URL = $ismember  ? (is_null($htmlURL) ? $pdfURL : $htmlURL) : $dsURL; 
  57.  
  58.                     $table_row[] = "<td><a href = '$title_URL' onclick='window.open('$title_URL'); return false;'>$Title</a></td>";
  59.                                             $table_row[] = "<td>$Source</td>";
  60.  
  61.                     $table_row[] = "<td>$Authors</td>";    
  62.  
  63.                     $table_row[] = "<td>$Year</td>";    
  64.  
  65.                     $table_row[] = "<td>$Date</td>";
  66.                         if(is_null($pdfURL)){
  67.                                                     $table_row[] = "<td align='center'>N/A</td>";
  68.                         }
  69.                         else{
  70.                             $pdf_URL = $ismember ? $pdfURL : $dsURL; 
  71.  
  72.                        $table_row[] = "<td><a href='<$pdf_URL' onclick='window.open('$pdf_URL'); return false;'><?= generate_img_tag('icon_small_pdf', 17, 17, NULL, 'icon17p')  ?></a></td>";
  73.  
  74.                             //<?php 
  75.                         } // end if_else    
  76.                         if (is_null($htmlURL)) {
  77.                                                         $table_row[] = "<td align='center'>N/A</td>";
  78.                         }
  79.                         else {
  80.                             $html_URL = $ismember ? $htmlURL : $dsURL; 
  81.  
  82.                                                 $table_row[] = "<td><a href='$html_URL' onclick='window.open('$html_URL '); return false;'><?= generate_img_tag('icon_small_pdf', 17, 17, NULL, 'icon17p')  ?></a></td>";
  83.  
  84.                          //<?php
  85.                         } #end if else(is_null($htmlURL))
  86.                                         $table_row[] = "</tr>";
  87.                     $alternate_row = !$alternate_row;
  88.                 }# end while()
  89.  
  90.                         $table_row[] = "</table>";
  91.                         /*$display_array = array(
  92.                                     "month"=>$month_array,
  93.                                     "source"=>$source_array,
  94.                                     "table"=>$table_row
  95.                                    ); 
  96.                                   */
  97.             /*$display_array = array(array(array($month_array)),
  98.                                    array(array($source_array)),
  99.                                    array(array($table_row))
  100.                                    );*/
  101.                         //print_r($display_array);
  102.             $display_array = array($month_array=>array($source_array=>array($table_row)));
  103.              print_r($display_array);
  104.         }# end if($num)
  105.     }#end  foreach()
  106.     $num_displayed_months++;
  107. } #end for()
  108.  
  109. I have used below code to declare my multidimensional array..
  110. /*$display_array = array(
  111.                                     "month"=>$month_array,
  112.                                     "source"=>$source_array,
  113.                                     "table"=>$table_row
  114.                                    ); 
  115.                                   */
  116.             /*$display_array = array(array(array($month_array)),
  117.                                    array(array($source_array)),
  118.                                    array(array($table_row))
  119.                                    );*/
  120.                         //print_r($display_array);
  121.             $display_array = array($month_array=>array($source_array=>array($table_row)));
  122.  
Dec 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: 8
my declaration is not working properly...

Need help to delcare multidimensionaly array

Thanks..
Dec 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.