Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to write this condition? Re: How to write this condition?

#126295
sayedtaqui
Member

Thanks Hugo , the script did not work but that gave me an idea
I have written another script

$title= mysql_real_escape_string($_POST);
if($_POST==NULL){
$slug=str_replace(‘ ‘, ‘-‘, $title);

$query=mysql_query(“SELECT * FROM pages WHERE slug=’$slug’ “);

if(mysql_num_rows($query)==0){
$slug2= $slug;
}else{
if(preg_match(‘/[a-zA-Z0-9-]+~[0-9]/’, $slug)){
$dash_pos= strrpos($slug, ‘~’);
$str_len= strlen($slug);
$after_dash= substr($slug,$dash_pos+1, $str_len );
$slug2= str_replace($after_dash,$after_dash+1,$slug);
}else{
$slug2=$slug;
$slug2.=’~’;
$slug2.=’1′;
}
}
//main if statememt ENDS
}else{
$slug= mysql_real_escape_string($_POST);
$slug2=str_replace(‘ ‘, ‘-‘, $slug);
}

$query= mysql_query(“INSERT INTO pages(pagename, content, pageId, slug, date, time, count) VALUES(‘$title’, ‘$content’, ‘$pageId’, ‘$slug2’, ‘$date’,’$time’, ‘$count’)”);

The code above is creating another slug
First it creates just ‘about-us’
then ‘about-us~1’
and if I do it again , it returns
‘about-us~1’ only.
What do I do?? ):