Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:46:52+00:00 2026-06-10T09:46:52+00:00

What i want to do is to create a permalink like system such as

  • 0

What i want to do is to create a permalink like system such as the wordpress permalink.

For example:

  $value = 'abc';
    if($query_result > 0){
       $value = 'abc1'; // if exists check abc2, abc3, abc4, abc5, etc. etc.
    } else{
      return $value
    }

The query results is a search for the number of rows $query_result = mysql_num_rows

At this moment i created this:

if(!empty($_POST['ajax'])){
    if($_POST['ajax'] == 'pages'){
        echo prettyName($_POST['title']);
    }
}

function prettyName($string)
{
    $echo = strtolower(str_replace(array('  ', ' '), '-', preg_replace('/[^a-zA-Z0-9 s]/', '', trim($string))));
    $sql = "SELECT * FROM posts WHERE post_pretty = '".$echo."'";
    $res = mysql_query($sql) or die (mysql_error());
    $num = mysql_num_rows($res);
    if($num){
        $echo = $echo.'-'.pretty2($echo, $num);
    }
    return $echo;
}

function pretty2($echo,$num,$i = 1)
{
    $sql = "SELECT * FROM posts WHERE post_pretty = '".$echo.'-'.$i."'";
    $res = mysql_query($sql) or die (mysql_error());
    $num = mysql_num_rows($res);
    if($num){
        $i++;
        $i = pretty2($echo,$num,$i);
    }
    return $i;
}

What does it do:

  1. check if $value ($_POST['title']) exists
  2. convert to a prettystring (by example: a b c = a-b-c)
  3. check if prettystring exists else +1 (by example: a-b-c exists, a-b-c-1 – a-b-c-9999)
  4. loop prettystring until free name doesn’t exists.

But what goes wrong is:

if i create a new Post for example:

new post 1 name = testpage // results in testpage
new post 2 name = testpage // results in testpage-1
new post 3 name = test-page // results in testpage-2 // should be test-page

if i create a new Post with to much whitespaces in it it also get’s wrong what could i use to remove all the white spaces? Tried to user TRIM function but that didn’t work. Or should i be using javascript to avoid that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:46:53+00:00Added an answer on June 10, 2026 at 9:46 am

    It will return abc if num rows are 0

    $value = 'abc';
    $query_result = mysql_query("SELECT * FROM `table`");
    $num_result = mysql_num_rows($query_result);
    
    if($num_result){
       $value = 'abc1';
    }
    

    PS. try to use PDO for your next development. A good Tutorial

    for your problem:

    $query_result = mysql_query("SELECT `name` FROM `Table1` ORDER BY `name` DESC LIMIT 1");
    $num_result = mysql_num_rows($query_result);
    
    if($num_result){
       $row = mysql_fetch_assoc($query_result);
       $value = (int)str_replace('abc', '', $row['name']);
       $value = 'abc'.($value+1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create wordpress website into which I want create user management... That means
I'm trying to create permalink like behavior for some article titles and i don't
I want create 32 views like above view. so that what i modify in
I want to create a nice Facebook, Twiter, G+ share buttons like they are
i want create multiple search where statement $where_search is a multiple condition from post
i want create a custom json data from the mssql 2008 results so that
I want create an application with animate button? how can i do? after click
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want create a excel with Apache POI in java and I must insert
i want create image animation , i have 50 images with png format now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.