Hi!
I'm having problems with an FAQ Script. It will only let me add 9 category files, and then rather than permitting me to add a tenth and so on, it will start again from 0. I'm need it to go beyond 9 up to as many as possible. This is wat the header code looks like:
<?php
$err="";
$totfound=0;
if(!isset($idx)) $idx=0;
function QuestionHere($cnt,$Q)
{
print "<b>$cnt. $Q</b><br>";
}
function AnswerHere($cnt,$A)
{
print "$A <font size=1><br><br></font>";
}
//read all with .faq ext.
$currdir=getcwd();
$dir=@opendir($currdir);
if(!$dir) print "Error dir $currdir";
$aCategory=array();
$n=0;
while($file=@readdir($dir))
{
if(substr($file,-4)==".faq")
{
$aCategory[]=$file;
//print substr($file,-4)." = $n. $aCategory[$n]<br>"; $n++;
}
}
sort($aCategory);
$nMaxCate=count($aCategory);
//Search
if(isset($searchtxt) && strlen($searchtxt)<3)
{
$err="Search at least 3 characters.";
$idx=-1;
$aFound=array();
}
elseif(isset($searchtxt) && $searchtxt!="")
{
$idx=-1;
$aFound=array();
for($a=0;$a<$nMaxCate;$a++)
{
$nFirst=0;
$ccfile=$currdir."/".$aCategory[$a];
$fp=@fopen($ccfile,"r");
if(!@fp) {print "Error reading ".$currdir."/".$aCategory[$a]; exit;}
$QorA=0;
$cnt=1;
$TempQ="";
$okenter=0;
while(!feof($fp))
{
$ln=fgets($fp,5000);
if(trim($ln)!="")
{
if(stristr($ln,$searchtxt) || $okenter==1)
{
if($nFirst==0)
{
$cCate=str_replace("_"," ",$aCategory[$a]);
$cCate=substr(substr($cCate,1),0,-4);
$aFound[]="@CATEGORY@$cCate";
$nFirst=1;
}
if($QorA==0) //Question
{
$QorA=1;
$okenter=1;
$totfound++;
}
else
{
$QorA=0;
if($okenter==0)
{
$totfound++;
$TempQ=str_replace($searchtxt,"<font color='000080'>$searchtxt</font>",$TempQ);
$aFound[]=$TempQ;
}
$okenter=0;
}
$ln=str_replace($searchtxt,"<font color='000080'>$searchtxt</font>",$ln);
$aFound[]=$ln;
}
else
{
if($QorA==0) {$TempQ=$ln; $QorA=1;}
elseif($QorA==1) {$QorA=0; $TempQ="";}
}
}
}
}
}
?>
The script also lets you search all categories and entries for a specific answer.
<?php
for($a=0;$a<$nMaxCate;$a++)
{
$cCate=str_replace("_","<font color=#ffffff>_</font>",$aCategory[$a]);
$cCate=substr(substr($cCate,1),0,-4);
$$cCate=strtoupper($file);
if($a==$idx) {print "[<b><font color='#BF963E'>$cCate</font></b>] "; $cSelectedCate=$cCate;}
else print "[<a href='faq.php?idx=$a'>$cCate</a>] ";
}
?>
<form method="POST" action="faq.php">
<b>Search :</b>
<input type="text" name="searchtxt" size="20" style="font-size: 8pt">
<input type="submit" value="Go" name="Search" style="font-size: 8pt">
</form>
Finally, the script will post your results:
<?php
if($idx>=0)
{
print "<font size='3' color='#1F356E'><b>$cSelectedCate<br><br></b></font>";
$fp=@fopen($aCategory[$idx],"r");
if(!$fp) {print "Error reading ".$currdir."/".$aCategory[$a]; exit;}
$QorA=0;
$cnt=1;
while(!feof($fp))
{
$ln=fgets($fp,500);
if(trim($ln)!="")
{
if($QorA==0) {QuestionHere($cnt,$ln); $QorA=1;}
else {AnswerHere($cnt,$ln); $QorA=0; $cnt++;}
}
}
}
else
{ // SEARCH MODULE
$nMaxFound=count($aFound);
if($nMaxFound==0)
{
if($err!="") print "<br><font color='cc0000'>$err</font>";
else print "No search found for <b>$searchtxt</b>";
}
else
{
print "<font color=#000080 size=3>Search \"<b>$searchtxt</b>\", found <b>$totfound</b> topics.<br></font>";
$cnt=1;
$QorA=0;
for($a=0;$a<$nMaxFound;$a++)
{
if(substr($aFound[$a],0,10)=="@CATEGORY@")
{
$cSelectedCate=substr($aFound[$a],10);
print "<br><font size='3' color='#1F356E'><b>$cSelectedCate<br></b></font>";
$QorA=0;
}
else
{
if($QorA==0) {QuestionHere($cnt,$aFound[$a]); $QorA=1;}
else {AnswerHere($cnt,$aFound[$a]); $QorA=0; $cnt++;}
}
}
}
}
?>
I have no problems with the search and post, but only with this unknown limitation of files I can make into categories. Each category derives from a simple text file. This is not database driven, which is exactly what I need. Can anyone help me solve this file limitation?
Thanks!!!