Need assistnace with Mod_Rewrite for a Directory Script.

New to mod_rewrite? This is a good place to start.

Need assistnace with Mod_Rewrite for a Directory Script.

Postby juke » Mon Jul 26, 2004 6:22 am

I want to use the free directory script from http://www.biz-directory.org/
For my web link section of my site. But people are telling me they will not trade link with me until I do a mod_rewrite. I know enough about php/html to be dangerous but I'm a bit confused on how the varibles structure work for the mod_rewrite. The doc on Apache.org is a little greek too (too techy)


For easy of use I think I would only want to to a rewrite of the index.php. For link exchange purposes thats all that I need to rewrite.

/index.php?c=1 indicates sub category of the directory.

Then if the subcatgory goes to a additional page the url is
/index.php?c=24&s=11

Here is the code from the index.php script that I need help with:

<?
include ("config.php");
include ("include.php");
include ("lang.php");
session_start();
$c *= 1;
if ($c == 0) { $c = 1; };
$sql = mysql_query("SELECT name, title, description, pages, ref FROM {$prefix}categories WHERE id = $c");
$current_category = mysql_fetch_array($sql, MYSQL_ASSOC);
if (($c > 1) & !$current_category["name"]){
header("Location: {$dir}index.php");
};
if (!$current_category["name"]) { $current_category["name"] = "Directory Search"; };
if (!$current_category["title"]) { $current_category["title"] = $current_category["name"]; };
if (!$current_category["description"]) { $current_category["description"] = $current_category["name"]." ".$current_category["title"]; };
$last_category = false;
$ref = $c;
while(!$last_category){
$n_parent_categories += 1;
$sql = mysql_query("SELECT id, name, ref FROM {$prefix}categories WHERE id = $ref");
$parent_categories[$n_parent_categories-1] = mysql_fetch_array($sql, MYSQL_ASSOC);
if ($parent_categories[$n_parent_categories-1]["ref"] == 0){
$last_category = true;
}else{
$ref = $parent_categories[$n_parent_categories-1]["ref"];
};
};
$sql = mysql_query("SELECT {$prefix}categories.id, {$prefix}categories.name, COUNT({$prefix}pages.id) AS pages FROM {$prefix}categories LEFT JOIN {$prefix}pages ON {$prefix}pages.category = {$prefix}categories.id AND {$prefix}pages.accepted = 'y' WHERE ref = $c GROUP BY {$prefix}categories.id ORDER BY {$prefix}categories.name");
$n_subcategories = mysql_num_rows($sql);
for ($x = 0; $x < $n_subcategories; $x++){
$subcategories[$x] = mysql_fetch_array($sql, MYSQL_ASSOC);
};
$sql = mysql_query("SELECT {$prefix}categories.id, {$prefix}categories.name, COUNT({$prefix}subcategories.id) AS subcategories FROM {$prefix}categories LEFT JOIN {$prefix}categories AS {$prefix}subcategories ON {$prefix}subcategories.ref = {$prefix}categories.id WHERE {$prefix}categories.ref = $c GROUP BY {$prefix}categories.id ORDER BY {$prefix}categories.name");
for ($x = 0; $x < $n_subcategories; $x++){
$subcategories[$x]["subcategories"] = mysql_result($sql, $x, "subcategories");
};

if ($current_category["pages"] == "y"){
if ($s == 0) { $s = 1; };
$n = 10;
$sql = mysql_query("SELECT COUNT(*) AS total_pages FROM {$prefix}pages WHERE category = $c AND accepted = 'y'");
$total_pages = mysql_result($sql,0,"total_pages");
if ($total_pages > 0){
$sql = mysql_query("SELECT id, url, title, description FROM {$prefix}pages WHERE category = $c AND accepted = 'y' ORDER BY title LIMIT ".($s-1).",$n");
$n_pages = mysql_num_rows($sql);
for ($x = 0; $x < $n_pages; $x++){
$pages[$x] = mysql_fetch_array($sql, MYSQL_ASSOC);
};
};
};
$e = min($s + $n - 1, $s + $n_pages - 1);
?>
<HTML>
<HEAD>

<BODY>


<DIV CLASS="main">
<DIV CLASS="heading">
<?
include ("starting_html.php");
?><BR><center>
<B>&#187; Save 50% of Base Submission Price First 50 sites only $7.50 per submission</B><P></center>

<H1><? echo $current_category["name"]?></H1>



<?
if ($c != 1){
echo '<DIV CLASS="heading_path">'."\r\n";
for ($x = $n_parent_categories-1; $x >= 1; $x--){
if ($x != $n_parent_categories-1) { echo " > "; };
if ($parent_categories[$x]["id"] == 1){
echo '<A HREF="'.$dir.'index.php">'.$parent_categories[$x]["name"].'</A>';
}else{
echo '<A HREF="'.$dir.'index.php?c='.$parent_categories[$x]["id"].'">'.$parent_categories[$x]["name"].'</A>';
};
};
echo ' > '.$current_category["name"];
echo "</DIV>\r\n";
};
?>
</DIV>


<DIV CLASS="search">
<FORM METHOD="get" ACTION="search.php">
<DIV CLASS="search_controls">
<INPUT TYPE="text" NAME="q" MAXLENGTH=100 CLASS="search_controls_text">
<INPUT TYPE="submit" VALUE="<? echo $t02?>" CLASS="search_controls_button">
</DIV>

<?
if ($current_category["pages"] == "y" || $HTTP_SESSION_VARS['admin']){
echo '<DIV CLASS="search_add">'."\r\n";
if($current_category["pages"] == "y"){
echo '<A HREF="'.$dir.'add_url.php?c='.$c.'">'.$t03.'</A>'."\r\n";
};
if($HTTP_SESSION_VARS['admin']){
echo '<A HREF="'.$dir.'admin_edit.php?c='.$c.'">'.$t04.'</A>'."\r\n";
};
echo "</DIV>\r\n";
};
?>
</FORM>
</DIV>



<?
if ($n_subcategories > 0){
echo '<DIV CLASS="categories">'."\r\n";
echo '<DIV CLASS="categories_text">'.$t01.' "'.$current_category["name"].'":</DIV>'."\r\n";
$t = ceil($n_subcategories/2);
echo '<DIV CLASS="categories_blocks">'."\r\n";
echo '<DIV CLASS="categories_blocks_left">'."\r\n";
for ($x = 0; $x < $t; $x++){
echo '<DIV CLASS="categories_category">&#187; <DIV CLASS="categories_category_title"><A HREF="'.$dir.'index.php?c='.$subcategories[$x]["id"].'">'.$subcategories[$x]["name"].'</A> </DIV>('.$subcategories[$x]["subcategories"].'/'.$subcategories[$x]["pages"].')</DIV>'."\r\n";
};
echo "</DIV>\r\n";
echo '<DIV CLASS="categories_blocks_right">'."\r\n";
if ($n_subcategories > 1){
for ($x = $t; $x < $n_subcategories; $x++){
echo '<DIV CLASS="categories_category">&#187; <DIV CLASS="categories_category_title"><A HREF="'.$dir.'index.php?c='.$subcategories[$x]["id"].'">'.$subcategories[$x]["name"].'</A> </DIV>('.$subcategories[$x]["subcategories"].'/'.$subcategories[$x]["pages"].')</DIV>'."\r\n";
};
}else{
echo " \r\n";
};
echo "</DIV>\r\n";
echo "</DIV>\r\n";
echo "</DIV>\r\n";
};
if ($current_category["pages"] == "y"){
if ($n_pages > 0){
echo '<DIV CLASS="pages">'."\r\n";
echo '<DIV CLASS="pages_results">'.$t05a.' '.$s.' - '.$e.' '.$t05b.' '.$total_pages.' '.$t05c.' "'.$current_category["name"].'":</DIV>'."\r\n";
for ($x = 0; $x < $n_pages; $x++){
echo '<DIV CLASS="pages_page">'."\r\n";
echo '<DIV CLASS="pages_page_title"><b>&#187;</b> <A target="_blank" title="'.$pages[$x]["title"].'" HREF="'.$pages[$x]["url"].'">'.$pages[$x]["title"].'</A></DIV>'."\r\n";
echo '<DIV CLASS="pages_page_description">'.$pages[$x]["description"].'</DIV>'."\r\n";
echo '<b><DIV CLASS="pages_page_url">'.$pages[$x]["url"].'</DIV></b>'."\r\n";
echo "</DIV>\r\n";
};
echo "</DIV>\r\n";
}else{
echo '<DIV CLASS="pages">'."\r\n";
echo '<DIV CLASS="pages_results">'.$t06.' "'.$current_category["name"].'"</DIV>'."\r\n";
echo "</DIV>\r\n";
};
if ($s != 1 || $e != $total_pages){
function query($s){
global $c;
if ($c != 1) { $query = "?c=$c"; };
if (($c != 1) & $s != 1){
$query .= "&s=$s";
}elseif ($s != 1){
$query = "?s=$s";
};
return $query;
};
echo '<DIV CLASS="options">'."\r\n";
if ($s != 1){
$previous = $s - $n;
echo '<A HREF="'.$dir.'index.php'.query($previous).'">'.$t07.'</A>'."\r\n";
};
for ($x = 1; $x <= ceil($total_pages/$n); $x++){
$current = ($x-1) * $n + 1;
if ($current == $s){
echo $x."\r\n";
}else{
echo '<A HREF="'.$dir.'index.php'.query($current).'">'.$x.'</A>'."\r\n";
};
};
if ($e < $total_pages){
$next = $s + $n;
echo '<A HREF="'.$dir.'index.php'.query($next).'">'.$t08.'</A>'."\r\n";
};
echo "</DIV>\r\n";
};
};
include ("links.php");
?>


</DIV>
</BODY>
</HTML>


I know that the href parts are the only items that need to be changed but I just wanted to include this to to make sure.

thanks.

So much.
James
juke
 
Posts: 1
Joined: Mon Jul 26, 2004 5:30 am
Location: Charlotte, NC

Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 94 guests

cron