Note that there are some explanatory texts on larger screens.

plurals
  1. POphp permalink like wordpress permalink
    primarykey
    data
    text
    <p>What i want to do is to create a permalink like system such as the wordpress permalink.</p> <p>For example:</p> <pre><code> $value = 'abc'; if($query_result &gt; 0){ $value = 'abc1'; // if exists check abc2, abc3, abc4, abc5, etc. etc. } else{ return $value } </code></pre> <p>The query results is a search for the number of rows <code>$query_result = mysql_num_rows</code></p> <p>At this moment i created this:</p> <pre><code>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; } </code></pre> <p>What does it do:</p> <ol> <li>check if <code>$value</code> (<code>$_POST['title']</code>) exists</li> <li>convert to a prettystring (by example: a b c = a-b-c)</li> <li>check if prettystring exists else +1 (by example: a-b-c exists, a-b-c-1 - a-b-c-9999)</li> <li>loop prettystring until free name doesn't exists.</li> </ol> <p>But what goes wrong is:</p> <p>if i create a new Post for example:</p> <pre><code>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 </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload