php - echo function and edit for permalink -


i want make change in function

    <?php  function add_post($title,$contents,$category){     $title      = mysql_real_escape_string($title);     $contents   = mysql_real_escape_string($contents);     $category   = (int)$category;      mysql_query("insert `posts` set                 `cat_id`     = {$category},                 `title`      = '{$title}',                 `contents`   = '{$contents}',                 `date_posted`= now()"); }  function edit_post($id,$title,$contents,$category){     $id         = (int)$id;     $title      = mysql_real_escape_string($title);     $contents   = mysql_real_escape_string($contents);     $category   = (int)$category;      mysql_query("update `posts` set                 `cat_id`     = {$category},                 `title`      = '{$title}',                 `contents`   = '{$contents}'                 `id` = {$id}");   }  function add_category($name){   $name = mysql_real_escape_string($name);    mysql_query("insert `categories` set `name` = '{$name}'"); }  function delete($table, $id){     $table = mysql_real_escape_string($table);     $id    = (int)$id;      mysql_query("delete `{$table}` `id`= {$id} ");  }  function get_posts($id = null, $cat_id = null){     $posts = array();     $query = "select               `posts`.`id` `post_id` ,                `categories`.`id` `category_id`,                `title`,`contents`,`date_posted`,                `categories`.`name`                `posts`                inner join `categories` on `categories`.`id` = `posts`.`cat_id` " ;     if(isset($id)){         $id = (int)$id;         $query .= " `posts`.`id` = {$id} ";              }     if(isset($cat_id)){         $cat_id = (int)$cat_id;         $query .= " `cat_id` = {$cat_id} ";              }               $query .= "order `post_id` desc";      $query = mysql_query($query);      while($row = mysql_fetch_assoc($query)){     $posts[] = $row;    }    return $posts; }  function get_categories($id = null){    $categories = array();     $query = mysql_query("select `id`,`name` `categories`");     while($row = mysql_fetch_assoc($query)){     $categories[] = $row;    }     return $categories; }  function category_exists($field,$name){     $name = mysql_real_escape_string($name);     $field = mysql_real_escape_string($field);      $query = mysql_query("select count(1) categories `{$field}` = '{$name}'");      return(mysql_result($query,0) == 0)?false : true; }  

and want permalink domain.com/watch/(movie_name)/episode-x/

i think need function permalinks .htaccess not working? (the function not mine want know good? secure?

in case, assuming .htaccess part working, doing string concatenation generate permalink parts.

function generate_permalink($cat_name, $id = null) {     $permalink = "http://localhost/blog/watch/$cat_name";     if ($id) {         $permalink = $permalink . '/episode/' . str_pad($id, 3, '0', str_pad_left);     }     return $permalink; } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -