FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


php coding needed





vignesh_natraj
can anyone rewrite http://www.centraldirectory.net/showcats.php?sbcat_id=49
to
http://www.centraldirectory.net/corresponding_category_name/
if you can do it please PM and i will send you the necessary files.
DoctorBeaver
I got a "Page not found" type error on the 2nd link. Even so, what exactly is it you want re-written?
n0obie4life
He wants mod_rewrite.
vignesh_natraj
yes i need to change /showcats.php?sbcat_id= to /categoryname
using changes in php script
vignesh_natraj
Quote:
<?php
include_once "myconnect.php";

if(isset($_REQUEST["cid"]))
{
$cat_query=mysql_query("Select * from sb_host_categories where sb_pid=" . $_REQUEST["cid"]);
$rs=mysql_num_rows($cat_query);
if($rs<=0)
{
header("Location:"."search_result.php?cid=".$_REQUEST["cid"]);
die();
}
}

function main()
{

$sb_suspended_ids='-2'; //'coz -1 is used 2 denote admin plans
$sbq_sus="select * from sb_host_members where sb_suspended!='no'";
$sbrs_sus=mysql_query($sbq_sus);
while($sbrow_sus=mysql_fetch_array($sbrs_sus))
$sb_suspended_ids.=", ".$sbrow_sus["sb_id"];

$config=mysql_fetch_array(mysql_query("select * from sb_host_config"));
$cid=0;
if(isset($_REQUEST["cid"])&&($_REQUEST["cid"]<>""))
{
$cid=$_REQUEST["cid"];
}

$catname="";
$category=0;

$cat_query=mysql_query("Select * from sb_host_categories where sb_id=" . $cid );
if ($cat=mysql_fetch_array($cat_query))
{
$catname=$cat["sb_cat_name"];
$category=$cat["sb_id"];
}

$catpath="";
$cat_query=mysql_query("Select * from sb_host_categories where sb_id=" . $cid );
while ($rs=mysql_fetch_array($cat_query))
{
$catpath =" > <a href=\"browsecats.php?cid=" . $rs["sb_id"] . "\">" .$rs["sb_cat_name"]."</a>".$catpath;
$cat_query=mysql_query("Select * from sb_host_categories where sb_id=" . $rs["sb_pid"] );

}
?><table width="100%" border="0" cellspacing="10" cellpadding="2" class="maintablestyle">
<tr>
<td valign="top"><table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="onepxtable">

<form name="form1" method="post" action="search_result.php">
<tr> <td align="center" valign="middle" class="innertablestyle"><br>
<input name="keyword" type="text" size="25"> <select name="cid" id="cid" >
<option value="0">Choose a category</option>
<?
$rs_query=mysql_query("select * from sb_host_categories order by sb_pid");
while($rst=mysql_fetch_array($rs_query))
{
echo $rst['sb_id'];
$cat_path="";
$child=mysql_fetch_array(mysql_query("select * from sb_host_categories where sb_pid=".$rst["sb_id"]));
if($child)
{
continue;
}
$cat_path.=$rst["sb_cat_name"];
$par=mysql_query("select * from sb_host_categories where sb_id=".$rst["sb_pid"]);
while($parent=mysql_fetch_array($par))
{
$cat_path=$parent["sb_cat_name"]."-".$cat_path;
$par=mysql_query("select * from sb_host_categories where sb_id=".$parent["sb_pid"]);
}
?>
<option value="<? echo $rst["sb_id"];?>" ><? echo $cat_path;?></option>
<?
}
?>
</select>
<font class='normal'>
<input name="show_save" type="hidden" id="show_save" value="yes">
</font>
<input type="submit" name="Submit" value="Search">
<a href="advance_search.php" class="small_link">Advance Search</a><br> &nbsp;
</td>
</tr>
</form>
<tr>
<td height="25" valign="middle" class="alternatecolor">&nbsp;<a href="index.php">Home</a><?php echo $catpath;?></td>
</tr>
</table></td>
</tr>
<tr>
<td valign="top"> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td><font class="normal"><b>Browse Category</b></font></td>
</tr>
<tr >
<td class="onepxtable"><table width="100%" border="0" cellspacing="1" cellpadding="2" class="innertablestyle">
<?

$cats_sql="select * from sb_host_categories where sb_pid=$cid ";
if($config["sb_cat_listing"]=="alpha")
{
$cats_sql.=" order by sb_cat_name";
}
else
{
$cats_sql.=" order by sb_order_index";
}
$cats_query=mysql_query($cats_sql);
$cnt=1;
$sb_total_children='-1'; //takes care of all the children of current cid that came
while($cats=mysql_fetch_array($cats_query))
{

$rst_query=mysql_query("Select * from sb_host_categories where sb_pid=".$cats["sb_id"] );
$clist=$cats["sb_id"];
while ( $rst=mysql_fetch_array($rst_query) )
{
$clist.="," . $rst["sb_id"];
$thislist="-1," . $rst["sb_id"];
while ( $rst=mysql_fetch_array($rst_query) )
{
$clist.="," . $rst["sb_id"];
$thislist.="," . $rst["sb_id"];
//echo $rst["sbcat_id"];
}
$rst_query=mysql_query("Select * from sb_host_categories where sb_pid in (" . $thislist . ")" );
}

$sb_total_children.=",".$clist;
//mysql_query("select * from sb_host_categories")
$sbcat_str= " and sb_cat IN (" .$clist . ")" ;
$sbq_host_plan="select * from sb_host_plans where sb_approved='yes' and sb_host_id not in ($sb_suspended_ids) $sbcat_str and (auction_period= -1 or UNIX_TIMESTAMP(DATE_ADD(sb_posted_on,INTERVAL auction_period DAY))>UNIX_TIMESTAMP(now()))";
$sbrow_host_cat=mysql_query($sbq_host_plan);
$sbtotal=mysql_num_rows($sbrow_host_cat);

//die();
if($cnt%3==1)
{
?>
<tr>
<td width="20">&nbsp;</td>
<?
}
?>
<td align="left"><font class='normal'> <a href="browsecats.php?cid=<? echo $cats["sb_id"];?>">
<? echo $cats["sb_cat_name"]; ?></a>(<? echo $sbtotal; ?>)</font></td>
<?
if($cnt%3==0)
{
?>
</tr>
<?
}
$cnt++;
}
?>
</table></td>
</tr>
</table></td>
</tr>
<?php

$sbrow_leaf=mysql_query("select * from sb_host_categories where sb_pid=$cid");
$max_rs=mysql_num_rows($sbrow_leaf);
//echo $max_rs;
$clist="-1";
$leaf_list='-1';
$count=1;
while($leaf_rs=mysql_fetch_array($sbrow_leaf))
{ //echo "catid".$rs["sb_id"]."catid ";
$leaf_rs1=mysql_fetch_array(mysql_query("select * from sb_host_categories where sb_pid=".$leaf_rs["sb_id"]));

if(!$leaf_rs1)
$clist.=','.$leaf_rs["sb_id"];
else
{
$leaf_list.=','.$leaf_rs["sb_id"];}
//echo "----$count----".$leaf_list."=========";
if($count==$max_rs)
{
//$sbq_leaf="Select * from sb_host_categories where sb_pid in (" . $leaf_list . ")" ;
//echo $sbq_host_plan;
$sbrow_leaf=mysql_query("Select * from sb_host_categories where sb_pid in (" . $leaf_list . ")" );
$leaf_list='-1';
$max_rs=mysql_num_rows($sbrow_leaf);
//echo $max_rs;
$count=0;

}
$count++;
}


$query123="select * from sb_host_plans where sb_approved='yes' and sb_featured='yes' and sb_cat in ($clist) and (auction_period= -1 or UNIX_TIMESTAMP(DATE_ADD(sb_posted_on,INTERVAL auction_period DAY))>UNIX_TIMESTAMP(now()))";
// echo $query123;
$ff_plans_q=mysql_query($query123);

$num_rows=mysql_num_rows($ff_plans_q);
//echo $num_rows;
if($num_rows>0)
{
?>
<tr>
<td valign="top">

<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="onepxtable">
<tr class="titlestyle">
<td width="22%">&nbsp;Featured Plans</td>
<td width="19%">&nbsp;Monthly Fee</td>
<td width="16%">&nbsp;Setup Fee</td>
<td width="19%">&nbsp;Disk Space</td>
<td width="24%">&nbsp;Number of Databases</td>
<!--td>&nbsp;</td-->
</tr>
<?php

//echo $sb_total_children;
$max_allowed=$config["sb_featured_cnt"];

$number[0]=-1;
if($num_rows>$max_allowed)
{
for($i=0;$i<$max_allowed;$i++)
{
$unique=0;
while($unique==0)
{
$j=rand(0,$num_rows-1);
for($k=0;$k<count($number);$k++)
{
//echo $j;
if($number[$k]==$j)
break;
}
if($k>(count($number)-1))
{
$unique=1;
}
}
$number[$i]=$j;

}
}// end if num > no_allowed
/*for($k=0;$k<count($number);$k++)
{
echo $number[$k]." ";
}*/

$row=0;
$cnt=0;
$ff_plans=mysql_fetch_array($ff_plans_q);
while (($ff_plans)&&($cnt<$max_allowed))
{
$display=0;
if($num_rows>$max_allowed)
{
for($k=0;$k<count($number);$k++)
{
if($number[$k]==$row)
{
$display=1;
}
}
}
else
{
$display=1;
}
if($display==1)
{
$comp=mysql_fetch_array(mysql_query("select comp from sb_host_members where sb_id=".$ff_plans["sb_host_id"]));
//where sb_id=".$ff_plans["sb_company_id"]));

$rec_class="innertablestyle";
if($cnt%2==0)
{ $rec_class="alternatecolor"; }
if($ff_plans["sb_highlight"]=="yes")
{
$rec_class="highlighted";
if($cnt%2==0)
{ $rec_class="highlighted1"; }
}

?>
<tr class="<?php echo $rec_class;?>" height="25">
<td>&nbsp;<font class="normal"><a href="view_plan.php?sb_id=<?php echo $ff_plans["sb_id"];?>"><?php
if($ff_plans["sb_bold"]=="yes")
{ echo "<b>";}
if(strlen($ff_plans["sb_title"])>20)
echo substr($ff_plans["sb_title"],0,20)."...";
else
echo $ff_plans["sb_title"];
if($ff_plans["sb_bold"]=="yes")
{ echo "</b>";}
?></a></font></td>
<td><font class="normal">&nbsp;<?php
//if($comp["sb_show_profile"]=="yes")
//{ echo "<a href='view_profile.php?id=".$comp["sb_id"]."'>";}
if($ff_plans["sb_bold"]=="yes")
{ echo "<b>";}
if ( $ff_plans["sb_mprice"]== -1)
echo "Unlimited";
else
echo $config["sb_fee_symbol"].$ff_plans["sb_mprice"];
if($ff_plans["sb_bold"]=="yes")
{ echo "</b>";}
//if($comp["sb_show_profile"]=="yes")
//{ echo "</a>";}
?></font></td>
<td><font class="normal">&nbsp;<?php
//if($comp["sb_show_profile"]=="yes")
//{ echo "<a href='view_profile.php?id=".$comp["sb_id"]."'>";}
if($ff_plans["sb_bold"]=="yes")
{ echo "<b>";}
if ( $ff_plans["sb_setup_fee"]== -1)
echo "Unlimited";
else
echo $config["sb_fee_symbol"].$ff_plans["sb_setup_fee"];

if($ff_plans["sb_bold"]=="yes")
{ echo "</b>";}
//if($comp["sb_show_profile"]=="yes")
//{ echo "</a>";}
?></font></td>
<td><font class="normal">&nbsp;<?php
//if($comp["sb_show_profile"]=="yes")
//{ echo "<a href='view_profile.php?id=".$comp["sb_id"]."'>";}
if($ff_plans["sb_bold"]=="yes")
{ echo "<b>";}
if ( $ff_plans["sb_disk_space"]== -1)
echo "Unlimited";
else
echo $ff_plans["sb_disk_space"]." MB";

if($ff_plans["sb_bold"]=="yes")
{ echo "</b>";}
//if($comp["sb_show_profile"]=="yes")
//{ echo "</a>";}
?></font>
</td>
<td><font class="normal">&nbsp;<?php
// $query=mysql_num_rows(mysql_query("select * from sb_host_plandatabase where sb_plan_id=".$ff_plans["sb_id"]));
if($ff_plans["sb_bold"]=="yes")
{ echo "<b>";}
if($ff_plans["sb_database"]== -1)
echo 'Unlimited';
else
echo $ff_plans["sb_database"];

//echo $ff_plans["sb_database"];

if($ff_plans["sb_bold"]=="yes")
{ echo "</b>";}
?></font></td>
<!--td>&nbsp;</td-->
<?php
$cnt++;
}//if display
$ff_plans=mysql_fetch_array($ff_plans_q);
$row++;
}// end while
if($cnt==0)
{
?>
</tr>
<tr height="25">
<td colspan="5" align="center" class="innertablestyle"> <font class='normal'>No
plans found in this section</font></td>
</tr>
<?php
}
?>
</table></td>
</tr>
<? }
?>
</table>
<?php
}
include_once'template.php';
?>

i am very new to php so i though i will get help from experts i am not a lazy guy but i tried two days of tweakink with the codes with my c++ knowledge but it is of no use
can some one do change from ID to name
ie change
Quote:
http://www.hostdir.us/browsecats.php?cid=5

to
Quote:
http://www.hostdir.us/browsecats.php?catname=cat_name/

in this case cat_name is ASP_Web_Hosting . i was able to get that "_" between names using pregreplace and str replace
please i have uploaded the browsecats.php visit the site for more details or PM me
thank you
gstreams
In order to rewrite the script we should know your database table structure.
Technicaly ... you want to replace cid=5 with catname=cat_name.

Code:
$cat_query=mysql_query(Select * from sb_host_categories where sb_pid=" . $_REQUEST["cid"]);


shoul come as :

Code:
$cat_query=mysql_query("Select * from sb_host_categories where sb_cat_name='" . $_REQUEST["cat_name"]."' ;");


You have more than one query searching for the id of the records.

Also you should change $_REQUEST["cid"] with $_REQUEST["cat_name"] everywhere in the script.

u should strip spaces from your category name when using them in links ... check php function : str_replace.

You should do this before rewriting.

Here you have a very comprehensible tutorial on URL rewriting :
http://www.alistapart.com/articles/urls/
vignesh_natraj
thank you i will take your suggestions and report later
mathiaus
I replied to this in your second topic Rolling Eyes
http://www.frihost.com/forums/viewtopic.php?p=296669#296669
vignesh_natraj
thats mod_rewrite but i should first put the cat_name into the url for the mod to work
correct me if i am wrong
Related topics
PHP Script needed
php coding
PHP Help Needed
PHP Help
Managing php pages
PHP Problem
how to make a php nav
What is the best tool to design websit?
affiliate tracking php script needed
VERY simple php script needed
Delphi IDE by CodeGear for PHP coding !!!
PHP Script Needed for 250 frih$
PHP Coding
PHP Form Question
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.