Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules
Author Message
transit
Regular
Regular



Joined: Jun 01, 2010
Posts: 69

PostPosted: Mon Oct 04, 2010 7:36 pm Reply with quote

So I started to try to change the way the FAQ module displays itself. It is a very useful module, however in reality I will never have more than 5-7 categories for my FAQ. So what I have tried to do is display all of the FAQ categories above every FAQ so that at any time the user can switch categories without having to go back to the "Main" page to select their category.

The problem it screws up the list of question links by showing the list for the last category on the list as opposed to the current FAQ selected. All of the Q and A's show correctly below, but the quick list of "Questions" is for the last category in the list for every category! Take a look here and see for yourself!

I could use as much help with this as possible! Thanks alot in advance! Smile

http://trott.ca/trott/faq-1-Frequently+Asked+Questions+for+Charters.html

Take this code here from the original FAQ

Code:


function ShowFaq($id_cat, $categories) {
   global $bgcolor2, $sitename, $prefix, $db, $module_name, $admin, $admin_file;
   $categories = htmlentities($categories);
   OpenTable();
   echo '<center><font class="content"><b>'.$sitename.' '._FAQ2.'</b></font></center><br /><br />'
      .'<a name="top"></a><br />'
      ._CATEGORY.': <a href="modules.php?name='.$module_name.'">'._MAIN.'</a> -&gt; '.$categories
      .'<br /><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'
      ._QUESTION.'</b></font></td></tr><tr><td colspan="2">';
   $id_cat = intval($id_cat);
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<a href="#'.$id.'">'.$question.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatGoEdit&amp;id='.$id.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatGoDel&amp;id='.$id.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table><br />';
}


And after line 78 of FAQ\index.php add this

Code:
   OpenTable();

   echo '<center><span class="option">'.$sitename.' '._FAQ2.'</span></center><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result2)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();


Which is pretty much the data copied from above in the index.php to show the categories on the main page for this module. I obviously need to change some syntax within to mesh the categories being displayed on the same page as each faq without interfering!

Here is the entire FAQ/index.php right now.


Code:


<?php

/***************************************************************************/
/* PHP-NUKE: Web Portal System                           */
/* ===========================                           */
/*                                          */
/* Copyright (c) 2002 by Francisco Burzi                        */
/* http://phpnuke.org                                 */
/*                                          */
/* ========================                           */
/* Based on PHP-Nuke Add-On                              */
/* Copyright (c) 2001 by Richard Tirtadji AKA King Richard               */
/*                       (rtirtadji@hotmail.com)         */
/*                       Hutdik Hermawan AKA hotFix      */
/*                       (hutdik76@hotmail.com)         */
/* http://www.nukeaddon.com                              */
/*                                          */
/* This program is free software. You can redistribute it and/or modify          */
/* it under the terms of the GNU General Public License as published by          */
/* the Free Software Foundation; either version 2 of the License.            */
/*                                          */
/***************************************************************************/
/*         Additional security & Abstraction layer conversion         */
/*                           2003 chatserv         */
/*      http://www.nukefixes.com -- http://www.nukeresources.com         */
/***************************************************************************/

if ( !defined('MODULE_FILE') ) {
   die('You can\'t access this file directly...');
}

require_once('mainfile.php');
$module_name = basename(dirname(__FILE__));
get_lang($module_name);

$pagetitle = '- '.$module_name;

if (!isset($myfaq)) {
   global $currentlang, $multilingual;
   if ($multilingual == 1) {
      $querylang = 'WHERE flanguage=\''.$currentlang.'\'';
   } else {
      $querylang = '';
   }
   include_once('header.php');
   OpenTable();
   echo '<center><span class="option">'._FAQ2.'</span></center><br /><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result2 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result2)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatEdit&amp;id_cat='.$id_cat.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatDel&amp;id_cat='.$id_cat.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();
   include_once('footer.php');
} else {
   include_once('header.php');
   ShowFaq($id_cat, $categories);
   ShowFaqAll($id_cat);
   CloseTable();
   include_once('footer.php');
}
die();

//Only functions after this line

function ShowFaq($id_cat, $categories) {
   global $bgcolor2, $sitename, $prefix, $db, $module_name, $admin, $admin_file;
   $categories = htmlentities($categories);

   OpenTable();
   echo '<center><span class="option">'.$sitename.' '._FAQ2.'</span></center><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result2)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();

   OpenTable();
   echo '<center><font class="content"><b>'.$sitename.' '._FAQ2.'</b></font></center><br /><br />'
      .'<a name="top"></a><br />'
      ._CATEGORY.': <a href="modules.php?name='.$module_name.'">'._MAIN.'</a> -&gt; '.$categories
      .'<br /><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'
      ._QUESTION.'</b></font></td></tr><tr><td colspan="2">';
   $id_cat = intval($id_cat);
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<a href="#'.$id.'">'.$question.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatGoEdit&amp;id='.$id.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatGoDel&amp;id='.$id.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table><br />';
}

function ShowFaqAll($id_cat) {
   global $bgcolor2, $prefix, $db, $module_name;
   $id_cat = intval($id_cat);
   echo '<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'._ANSWER.'</b></font></td></tr>';
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<tr><td><a name="'.$id.'"></a>'
         .'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<b>'.$question.'</b>'
         .'<div align="justify">'.$answer.'</div>'
         .'[ <a href="#top">'._BACKTOTOP.'</a> ]'
         .'<br /><br />'
         .'</td></tr>';
   }
   echo '</table><br /><br />'
      .'<div align="center"><b>[ <a href="modules.php?name='.$module_name.'">'._BACKTOFAQINDEX.'</a> ]</b></div>';
}

?>
 
View user's profile Send private message
kguske
Site Admin



Joined: Jun 04, 2004
Posts: 6437

PostPosted: Wed Oct 06, 2010 1:19 pm Reply with quote

Haven't had a chance to review the code, but it might a shortlinks issue. Have you tried it without using shortlinks?

_________________
I search, therefore I exist...
Only registered users can see links on this board! Get registered or login!
 
View user's profile Send private message
transit







PostPosted: Fri Oct 08, 2010 7:02 am Reply with quote

Definately not a shortlinks problem, here is my other site with SL disabled. Same problem.

http://completesolar.ca/modules.php?name=FAQ&myfaq=yes&id_cat=2&categories=FAQ
 
Palbin
Site Admin



Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania

PostPosted: Fri Oct 08, 2010 12:07 pm Reply with quote

It is because you are using $result2 instead of $result3in your ShowFaq function. From what I can tell you should not be passing $categories into the ShowFaq function. Also you should not be stripping slashes on data coming out of the database. I know it might have been that way before, but it is wrong.

_________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan. 
View user's profile Send private message
Palbin







PostPosted: Fri Oct 08, 2010 12:09 pm Reply with quote

Also when writing scripts you should have error reporting turned on because this problem would have shown up as an undefined variable.
 
transit







PostPosted: Fri Oct 08, 2010 5:46 pm Reply with quote

So your saying on line 85 i should change it to this?

Code:


   while ($row2 = $db->sql_fetchrow($result3)) {
 
Palbin







PostPosted: Fri Oct 08, 2010 7:19 pm Reply with quote

yes
 
transit







PostPosted: Mon Oct 11, 2010 10:15 am Reply with quote

No dice. This is my script with that minor change...

The FAQ can be seen here:
http://completesolar.ca/modules.php?name=FAQ&myfaq=yes&id_cat=2&categories=FAQ

Code:


<?php

/***************************************************************************/
/* PHP-NUKE: Web Portal System                           */
/* ===========================                           */
/*                                          */
/* Copyright (c) 2002 by Francisco Burzi                        */
/* http://phpnuke.org                                 */
/*                                          */
/* ========================                           */
/* Based on PHP-Nuke Add-On                              */
/* Copyright (c) 2001 by Richard Tirtadji AKA King Richard               */
/*                       (rtirtadji@hotmail.com)         */
/*                       Hutdik Hermawan AKA hotFix      */
/*                       (hutdik76@hotmail.com)         */
/* http://www.nukeaddon.com                              */
/*                                          */
/* This program is free software. You can redistribute it and/or modify          */
/* it under the terms of the GNU General Public License as published by          */
/* the Free Software Foundation; either version 2 of the License.            */
/*                                          */
/***************************************************************************/
/*         Additional security & Abstraction layer conversion         */
/*                           2003 chatserv         */
/*      http://www.nukefixes.com -- http://www.nukeresources.com         */
/***************************************************************************/

if ( !defined('MODULE_FILE') ) {
   die('You can\'t access this file directly...');
}

require_once('mainfile.php');
$module_name = basename(dirname(__FILE__));
get_lang($module_name);

$pagetitle = '- '.$module_name;

if (!isset($myfaq)) {
   global $currentlang, $multilingual;
   if ($multilingual == 1) {
      $querylang = 'WHERE flanguage=\''.$currentlang.'\'';
   } else {
      $querylang = '';
   }
   include_once('header.php');
   OpenTable();
   echo '<center><span class="option">'._FAQ2.'</span></center><br /><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result2 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result2)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatEdit&amp;id_cat='.$id_cat.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatDel&amp;id_cat='.$id_cat.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();
   include_once('footer.php');
} else {
   include_once('header.php');
   ShowFaq($id_cat, $categories);
   ShowFaqAll($id_cat);
   CloseTable();
   include_once('footer.php');
}
die();

//Only functions after this line

function ShowFaq($id_cat, $categories) {
   global $bgcolor2, $sitename, $prefix, $db, $module_name, $admin, $admin_file;
   $categories = htmlentities($categories);

   OpenTable();
   echo '<center><span class="option">'.$sitename.' '._FAQ2.'</span></center><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result3)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();

   OpenTable();
   echo '<a name="top"></a><br /><b>'
      ._CATEGORY.': '.$categories
      .'<br /><br /></b>'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'
      ._QUESTION.'</b></font></td></tr><tr><td colspan="2">';
   $id_cat = intval($id_cat);
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<a href="#'.$id.'">'.$question.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatGoEdit&amp;id='.$id.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatGoDel&amp;id='.$id.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table><br />';
}

function ShowFaqAll($id_cat) {
   global $bgcolor2, $prefix, $db, $module_name;
   $id_cat = intval($id_cat);
   echo '<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'._ANSWER.'</b></font></td></tr>';
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<tr><td><a name="'.$id.'"></a>'
         .'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<b>'.$question.'</b>'
         .'<div align="justify">'.$answer.'</div>'
         .'[ <a href="#top">'._BACKTOTOP.'</a> ]'
         .'<br /><br />'
         .'</td></tr>';
   }
   echo '</table><br /><br />'
      .'<div align="center"><b>[ <a href="modules.php?name='.$module_name.'">'._BACKTOFAQINDEX.'</a> ]</b></div>';
}

?>
 
Palbin







PostPosted: Mon Oct 11, 2010 10:58 am Reply with quote

You need to do another database query to get the proper category based on the id around line 97.
Code:


   echo '<a name="top"></a><br /><b>'
      ._CATEGORY.': '.$categories
      .'<br /><br /></b>'
 
transit







PostPosted: Thu Nov 04, 2010 4:37 pm Reply with quote

I added $categories into the global statement I am a little lost here with this Sad What I am guessing is happening is that the data I am posting for the faqcategories is already being pulled later on in the function so it is becoming redundent thus causing the error in showing the quick links for the faq questions?

I made the changes of both results being 3 instead of two on both instances below too I am guessing.

Code:


   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result3)) {

Any help Pablin would be greatly appreciated! Smile

Below is the function for this section of the FAQ.

Code:


function ShowFaq($id_cat, $categories) {
   global $bgcolor2, $sitename, $prefix, $db, $module_name, $admin, $admin_file, $categories;
   $categories = htmlentities($categories);

//Below table for category list insertion at the top of every faq

   OpenTable();
   echo '<center><span class="option">'.$sitename.' '._FAQ2.'</span></center><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result3)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();

   OpenTable();
   echo '<a name="top"></a><br /><b>'
      ._CATEGORY.': '.$categories
      .'<br /><br /></b>'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'
      ._QUESTION.'</b></font></td></tr><tr><td colspan="2">';
   $id_cat = intval($id_cat);
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<a href="#'.$id.'">'.$question.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatGoEdit&amp;id='.$id.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatGoDel&amp;id='.$id.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table><br />';
}
 
Palbin







PostPosted: Thu Nov 04, 2010 5:48 pm Reply with quote

You are trying to use the same variable "categories" for two different things. You can not do that. You are expecting it to hold the value passed by the url ....s&id_cat=3&categories=FAQ2, but then you you use it in your while loop:

Code:


   while ($row2 = $db->sql_fetchrow($result3)) {
      $id_cat = intval($row2['id_cat']);
      $categories = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname = urlencode($categories);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat.'&amp;categories='.$catname.'">'.$categories.'</a>';
      echo '<br />';
   }

So $categories is always going to be the last value from your while loop.

Remove $categories from the global statement and use a different variable name in the while loop. Perhaps use $category in the while loop as that is more representative to what is actually happening.
 
transit







PostPosted: Sat Nov 13, 2010 4:32 pm Reply with quote

Works alot better, turns out i had to change id_cat to id_cat2 as well as catname to catname2 as they are also redundant in the same function:

This is what I changed it to here:

Code:


function ShowFaq($id_cat, $categories) {
   global $bgcolor2, $sitename, $prefix, $db, $module_name, $admin, $admin_file, $categories;
   $categories = htmlentities($categories);

//Below table for category list insertion at the top of every faq

   OpenTable();
   echo '<center><span class="option">'.$sitename.' '._FAQ2.'</span></center><br /><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result3)) {
      $id_cat2 = intval($row2['id_cat']);
      $category = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname2 = urlencode($category);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat2.'&amp;category='.$catname2.'">'.$category.'</a>';
      echo '<br />';
   }
   echo '</td></tr></table>';
   CloseTable();

   OpenTable();
   echo '<a name="top"></a><br /><b>'
      ._CATEGORY.': '.$categories
      .'<br /><br /></b>'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'
      ._QUESTION.'</b></font></td></tr><tr><td colspan="2">';
   $id_cat = intval($id_cat);
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<a href="#'.$id.'">'.$question.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatGoEdit&amp;id='.$id.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatGoDel&amp;id='.$id.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table><br />';
}


It works fine, however now I have problems with the right link redirecting, thus to shortlinks.

Here is what I have changed in shortlinks however I must have something wrong!


.htaccess file
Code:


#FAQ
RewriteRule ^faq.html faq.html [L]
RewriteRule ^faq-([0-9]*)-([a-zA-Z0-9\+\&\-\/%[:punct:]\.\;\ ]*).html modules.php?name=FAQ&myfaq=yes&id_cat2=$1&category=$2 [L]


GT-FAQ.php
Code:


<?php
/************************************************************************
* Script:     TegoNuke(tm) ShortLinks
* Version:    1.0
* Author:     Rob Herder (aka: montego) of http://montegoscripts.com
* Contact:    montego@montegoscripts.com
* Copyright:  Copyright © 2006 by Montego Scripts
* License:    GNU/GPL (see provided LICENSE.txt file)
************************************************************************/
//GT-NExtGEn 0.4/0.5 by Bill Murrin (Audioslaved) http://gt.audioslaved.com (c) 2004
//Original Nukecops GoogleTap done by NukeCops (http://www.nukecops.com)

$urlin = array(
'"(?<!/)modules.php\?name=FAQ&amp;myfaq=yes&amp;id_cat2=([0-9]*)&amp;category=([a-zA-Z0-9\.\+\&\-\/\;% ]*)"',
'"(?<!/)modules.php\?name=FAQ"'
);

$urlout = array(
'faq-\\1-\\2.html',
'faq.html'
);

?>
 
Palbin







PostPosted: Sat Nov 13, 2010 5:02 pm Reply with quote

The link is not changing so why are you messing with shortlinks? The link you are making is still going to be the same you are just using different variables to create it.

It will still be
Code:
&myfaq=yes&id_cat=XX&category=XXXX


Not
Code:
&myfaq=yes&id_cat2=XX&category=XXXX
 
transit







PostPosted: Sun Nov 14, 2010 5:40 pm Reply with quote

You were right about the shortlinks I definately jumped the gun there.

However I did have to change the link to reflect catname2 and id_cat2 because I had to change those values since they are also changed in the while loop. I tried with just simply changing over categories to category and it would just display blank spaces where the links would be. The following script below works flawlessly! Smile


Code:


function ShowFaq($id_cat, $categories) {
   global $bgcolor2, $sitename, $prefix, $db, $module_name, $admin, $admin_file, $categories;
   $categories = htmlentities($categories);

//Below section for category list insertion at the top of every faq

   OpenTable();
   echo '<center><span class="option">'.$sitename.' '._FAQ2.'</span></center><br /><br />'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr><td bgcolor="'.$bgcolor2.'"><span class="option"><b>'._CATEGORIES.'</b></span></td></tr><tr><td>';
   $result3 = $db->sql_query('SELECT id_cat, categories FROM '.$prefix.'_faqcategories '.$querylang);
   while ($row2 = $db->sql_fetchrow($result3)) {
      $id_cat2 = intval($row2['id_cat']);
      $category = stripslashes(check_html($row2['categories'], 'nohtml'));
      $catname2 = urlencode($category);
      echo'<strong><big>&middot;</big></strong>&nbsp;<a href="modules.php?name='.$module_name.'&amp;myfaq=yes&amp;id_cat='.$id_cat2.'&amp;categories='.$catname2.'">'.$category.'</a>';
      echo '<br />';
   }
   echo '</td></tr></table><br />';

//End of section for category list insertion at the top of every faq

   echo '<a name="top"></a><b>'
      ._CATEGORY.': '.$categories
      .'<br /><br /></b>'
      .'<table width="100%" cellpadding="4" cellspacing="0" border="0">'
      .'<tr bgcolor="'.$bgcolor2.'"><td colspan="2"><font class="option"><b>'
      ._QUESTION.'</b></font></td></tr><tr><td colspan="2">';
   $id_cat = intval($id_cat);
   $result = $db->sql_query('SELECT id, id_cat, question, answer FROM '.$prefix.'_faqanswer WHERE id_cat=\''.$id_cat.'\'');
   while ($row = $db->sql_fetchrow($result)) {
      $id = intval($row['id']);
      $id_cat = intval($row['id_cat']);
      $question = stripslashes(check_html($row['question'], 'nohtml'));
      $answer = stripslashes($row['answer']);
      echo'<strong><big>&middot;</big></strong>&nbsp;&nbsp;<a href="#'.$id.'">'.$question.'</a>';
      if (is_admin($admin)) {
         echo ' [ <a href="'.$admin_file.'.php?op=FaqCatGoEdit&amp;id='.$id.'">'._EDIT.'</a>'
            .' | <a class="rn_csrf" href="'.$admin_file.'.php?op=FaqCatGoDel&amp;id='.$id.'&amp;ok=0">'._DELETE.'</a> ]';
      }
      echo '<br />';
   }
   echo '</td></tr></table><br />';
}
   CloseTable();
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules

View next topic
View previous topic
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 vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©