News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

[HELP NEEDED] My custom made SSI function doesn't show anything

Started by Angelotus, March 12, 2010, 11:23:54 AM

Previous topic - Next topic

Angelotus

Hi,


I have made this ssi function so that is shows the main categories with the subcategories of my custum mod. I get no errors, but it doesn't show anything. I am not a PHP expert, so I can use a little help of you experts please!




function template_getklifixcats2()


{
global $scripturl, $db_prefix, $txt, $settings, $modSettings, $context;   
global $amSettings, $galurl, $smcFunc;


$dbresult = $smcFunc['db_query']('', '
   SELECT a.description, a.icon, a.parent, a.num_items, a.id_klifixcat, a.hidden, a.approved, a.featured, a.a_order, a.name, a.klifixcat_of,            a.child_level, a.master       
   FROM {db_prefix}klifix_klifixcats AS a 
   LEFT JOIN {db_prefix}klifix_files AS f ON (f.id_file = a.icon)
   WHERE a.approved = 1   
   AND a.hidden = 0
   AND a.featured = 1
   AND a.child_level = 0
   ORDER BY a.name
   ASC LIMIT 50 




');


  $klifixcats = array();


  while ($row = $smcFunc['db_fetch_assoc']($dbresult))   
   {
     
   $klifixcats = $row['id_klifixcat'];
   $return[] = array (
   'name' => $row['name'],
   'description' => $row['description'],
   'href' => '<a href="' . $scripturl . '?action=klifix;sa=klifixcat;id=' . $row['id_klifixcat'] . '">' . $row['name'] . '</a>',
   'items' => $row['num_items']
   );


   }


   $smcFunc['db_free_result']($dbresult);


   if (empty($klifixcats))


      return array();




// get the subklifixcats


  $dbresult = $smcFunc['db_query']('', '
   SELECT a.description, a.icon, a.parent, a.num_items, a.id_klifixcat, a.hidden, a.approved, a.featured, a.a_order, a.name, a.klifixcat_of,            a.child_level, a.master       
   FROM {db_prefix}klifix_klifixcats AS a 
   LEFT JOIN {db_prefix}klifix_files AS f ON (f.id_file = a.icon)
   WHERE a.approved = 1   
   AND a.hidden = 0
   AND a.child_level = 1
   ORDER BY a.name
   ASC LIMIT 50 




');


   while ($row = $smcFunc['db_fetch_assoc']($dbresult))   
   {
     $subklifixcats[$row['parent']['id_klifixcat']] = $row;
   }
   while ($row = $smcFunc['db_fetch_assoc']($dbresult))   
   {
     
   $subklifixcats = $row['parent']['id_klifixcat'];
   $return[] = array (
   'name' => $row['name'],
   'description' => $row['description'],
   'href' => '<a href="' . $scripturl . '?action=media;sa=klifixcat;id=' . $row['id_klifixcat'] . '">' . $row['name'] . '</a>',
   'items' => $row['num_items']
   );


   }


   $smcFunc['db_free_result']($dbresult);


   if (empty($subklifixcats))


      return array();


   
   echo '<table class="collapse">
   <tr class="titlebg">
   <td valign="middle" ';
   if ($context['allow_admin'])
   echo 'colspan="3"';
   else
   echo 'colspan="2"';
   echo ' align="left" style="font-size: 9px; padding: 5px;">Category</td>
   <td valign="middle" align="right" style="font-size: 9px; padding: 5px;">Items</td>
   </tr>';


   $use_bg1 = false;
   foreach ($klifixcats as $klifixcat)
   {


   $use_bg1 = !$use_bg1;
         echo '<tr class="', ($use_bg1 ? 'windowbg10' : 'windowbg20'), '">';


   echo '<td align="left" width="64" style="padding: 5px;">
   <a class="normal" title="' . $klifixcat['description'] . '" href="' . $scripturl . '?action=klifix;sa=klifixcat;id=' . $klifixcat['id_klifixcat'] . '"><img src="' . $scripturl . '?action=media;sa=klifix;id=' . $klifixcat['id_klifixcat'] . ';icon" height="64" width="64" border="0" /></a></td>';


   if ($context['allow_admin'])
   echo '<td align="left">
   <a title="Edit" href="http://www.weeklyfun.nl/forum/index.php?action=klifix;area=sck;sa=edit;in=' . $klifixcat['id_klifixcat'] . '">[pic]</a>
   </td>';


   echo '<td align="left" style="padding: 5px;">
         <a class="normal" title="' . $klifixcat['description'] . '" href="' . $scripturl . '?action=klifix;sa=klifixcat;id=' . $klifixcat['id_klifixcat'] . '"><h3>'.$klifixcat['name'].'</h3></a>
        ' . $klifixcat['description'] . '
      </td>
      <td align="right" style="padding: 5px;"><b>'.$klifixcat['num_items'].'</b>
   </td>
      </tr>';


   if(!empty($subklifixcats) > 0)
        {
      foreach ($subklifixcats as $subklifixcat)
         {
      echo '<a title="' . $subklifixcat['description'] . '" href="' . $scripturl . '?action=klifix;sa=klifixcat;id=' . $subklifixcat['id_klifixcat'] . '">'.$subklifixcat['name'].'</a>&nbsp;%nbsp;';
             }
        }


   }


   echo '
         </table>';


}



What I want it to show is like this:


###### #####################################################################
###### #####################################################################
#IMAGE# ## MAIN CATEGORIE ######################################################
######  ### main categorie description and nr of items ####################################
######  ##### subcategorie (nr of items), subcategorie (nr of items), subcategorie (nr of items), etc #####
###########################################################################


Can someone please help me out with this?

Arantor

First up, you're referencing tables I don't recognise at all in SMF. Having proper indentation would probably help too.

And how is this being called?
Holder of controversial views, all of which my own.


Angelotus


Arantor

Neither {db_prefix}klifix_klifixcats nor {db_prefix}klifix_files are in SMF.
Holder of controversial views, all of which my own.


Angelotus

No, that is correct. I'm using that as example. Let's say that we call those smf_cat and smf_files, would that make a difference?

Arantor

Not really because without knowing a) what the hell those tables are and b) what they're supposed to contain (and whether the query actually makes sense) I have no idea whether the query is correct or not for the data and whether it's actually supposed to return rows or not, even before we go any further.
Holder of controversial views, all of which my own.


Advertisement: