...

View Full Version : What do I use, for or foreach??



sc0ttkclark
08-31-2006, 03:52 AM
function Build_htAccess ()
{
$result1=$this->DB_Query("select * from ".TABLE_PAGES." where parent_id='0' order by nav_order");
$count1=$this->DB_CountResult($result1);
$build1 = "php_flag register_globals on\nphp_value register_globals 1\n\n<Files .htaccess>\norder allow,deny\ndeny from all\n</Files>\n\nRewriteBase /\n\n#<DEFAULT>\nDirectoryIndex index.php index.htm index.asp index.shtml\n#</DEFAULT>\n\n";
for($x=0;$x<$count1;$x++)
{
$remove_tags = array(" ", "=", "+", ")", "(", "*", "&", "^", "%", "$", "#", "@", "!", "~", "`", "'", "\"", "\\", "/", ".", ",", "?", ";", ":", "[", "]", "{", "}", "|");
$id1 = $this->DB_Result($result1,$x,"id");
$link_text1 = strtolower(str_replace($remove_tags,"",str_replace(" ","-",str_replace(" "," ",strip_tags($this->DB_Result($result1,$x,"link_text"))))));
$layout1 = $this->DB_Result($result1,$x,"layout");
$upper_text = strtoupper($link_text1);
$build2 = "#<".$upper_text.">\n";
if($this->Pages_HasSubPages ($id1))
{
$result2=$this->DB_Query("select * from ".TABLE_PAGES." where parent_id='".$id1."' order by nav_order");
$count2=$this->DB_CountResult($result2);
for($y=0;$y<$count2;$y++)
{
$id2 = $this->DB_Result($result2,$y,"id");
$link_text2 = strtolower(str_replace($remove_tags,"",str_replace(" ","-",str_replace(" "," ",strip_tags($this->DB_Result($result2,$y,"link_text"))))));
$layout2 = $this->DB_Result($result2,$y,"layout");
if($this->Pages_HasSubPages ($id2))
{
$result3=$this->DB_Query("select * from ".TABLE_PAGES." where parent_id='".$id2."' order by nav_order");
$count3=$this->DB_CountResult($result3);
for($z=0;$z<$count3;$z++)
{
$id3 = $this->DB_Result($result3,$z,"id");
$link_text3 = strtolower(str_replace($remove_tags,"",str_replace(" ","-",str_replace(" "," ",strip_tags($this->DB_Result($result3,$z,"link_text"))))));
$layout3 = $this->DB_Result($result3,$z,"layout");
$build3 = "RewriteRule ^".$link_text1."/".$link_text2."/".$link_text3."/ index.php?id=".$id3."&layout=".$layout3."\nRewriteRule ^".$link_text1."/".$link_text2."/".$link_text3.".".HTACCESS_EXT." index.php?id=".$id3."&layout=".$layout3."\nRewriteRule ^".$link_text1."/".$link_text2."/".$link_text3." index.php?id=".$id3."&layout=".$layout3."\n";
}
$this->DB_FreeResult($result3);
}
$build4 = "RewriteRule ^".$link_text1."/".$link_text2."/ index.php?id=".$id2."&layout=".$layout2."\nRewriteRule ^".$link_text1."/".$link_text2.".".HTACCESS_EXT." index.php?id=".$id2."&layout=".$layout2."\nRewriteRule ^".$link_text1."/".$link_text2." index.php?id=".$id2."&layout=".$layout2."\n";
}
$this->DB_FreeResult($result2);
}
$build5 = "RewriteRule ^".$link_text1."/ index.php?id=".$id1."&layout=".$layout1."\nRewriteRule ^".$link_text1.".".HTACCESS_EXT." index.php?id=".$id1."&layout=".$layout1."\nRewriteRule ^".$link_text1." index.php?id=".$id1."&layout=".$layout1."\n";
}
$build6 = "#</".$upper_text.">\n";
$build = $build1.$build2.$build3.$build4.$build5.$build6;
$htcheck = @fopen("../.htaccess","w") or die("INSTALL ERROR - CANNOT CREATE .HTACCESS FILE");
@fwrite($htcheck,$build) or die("INSTALL ERROR - CANNOT WRITE TO .HTACCESS FILE");
@fclose($htcheck);
$this->DB_FreeResult($result1);
}


builds



php_flag register_globals on
php_value register_globals 1

<Files .htaccess>
order allow,deny
deny from all
</Files>

RewriteBase /

#<DEFAULT>
DirectoryIndex index.php index.htm index.asp index.shtml
#</DEFAULT>

#<CONTACT-ME>
RewriteRule ^contact-me/2/3/ index.php?id=9&layout=1
RewriteRule ^contact-me/2/3.xt index.php?id=9&layout=1
RewriteRule ^contact-me/2/3 index.php?id=9&layout=1
RewriteRule ^contact-me/2/ index.php?id=8&layout=1
RewriteRule ^contact-me/2.xt index.php?id=8&layout=1
RewriteRule ^contact-me/2 index.php?id=8&layout=1
RewriteRule ^contact-me/ index.php?id=6&layout=1
RewriteRule ^contact-me.xt index.php?id=6&layout=1
RewriteRule ^contact-me index.php?id=6&layout=1
#</CONTACT-ME>


---- But why does it only write "CONTACT-ME" the last row pulled from the database, and no other rows before it? Am I missing something here?

sc0ttkclark
08-31-2006, 05:20 AM
okay I accomplished it. How did I do it?

I moved this above the first "for":



$htcheck = @fopen("../.htaccess","w") or die("INSTALL ERROR - CANNOT CREATE .HTACCESS FILE");


and added this after each $buildNUMBER:



@fwrite($htcheck,$build) or die("INSTALL ERROR - CANNOT WRITE TO .HTACCESS FILE");


One must remember to include the build and write function just before it's corresponding for statement ends. After the last for statement ends, close it out with



@fclose($htcheck);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum