I need to update the column of a table.
I have this:
ID | title | slug_name
1 | The Winner is |
2 | Beautiful day |
I've to update the slug_name:
ID | title | slug_name
1 | The Winner is | the-winner-is
2 | Beautiful day | beautiful-day
So I created a function slug()
function slug($str) {
return strtolower(trim(preg_replace('/[^a-zA-Z0-9]+/', '-', $str), '-'));
}
and how can I return "title" in the function "slug"?
mysql_query("UPDATE table SET slug_name = '".slug(???title???)."'");
I tried also:
$items = mysql_query("SELECT title FROM table");
while($item = mysql_fetch_object($items)) {
mysql_query("UPDATE table SET slug_name = '".slug($item->title)."'");
}
But all rows return the same "slug_name".