Hi,
I'm having trouble with preg_replace and a mysql query. Here's my code :
$query = $db->query("SELECT style FROM ".$table_styles." WHERE id = '1'");
$r = $db->fetch_array($query);
$style_1 = $r[style];
$query = $db->query("SELECT id, name, description FROM
".$table_categories."");
while($r = $db->fetch_row($query)) {
$category_id = $r[0];
$category_name = $r[1];
$category_description = $r[2];
$style_1 = preg_replace('/\[url\]/', "index.php?catID=$category_id",
$style_1);
$style_1 = preg_replace('/\[title\]/', "$category_name", $style_1);
echo "$style_1\n";
echo "<BR>\n";
}
This is the schema for $table_styles
+----+-------------+-------------------------------------------------+------
-----------------------+
| id | name | description
| style |
+----+-------------+-------------------------------------------------+------
-----------------------+
| 1 | Title Links | The style for the title links on the main page.
| <a href="[url]">[title]</a> |
+----+-------------+-------------------------------------------------+------
-----------------------+
This is the schema for $table_categories
+----+------+------------------------------------------+-----------+--------
--+
| id | name | description
| picture | comments |
+----+------+------------------------------------------+-----------+--------
--+
| 1 | PHP | PHP is a powerful open source language. | icon3.gif |
0 |
| 2 | ASP | ASP is microsoft's dynamic web language.| icon2.gif |
0 |
+----+------+------------------------------------------+-----------+--------
--+
The script should loop and replace [url] and [title] with the relative id
and name from $table_categories, however when it is run, it gives out :
<a href="index.php?catID=1">PHP</a>
<BR>
<a href="index.php?catID=1">PHP</a>
<BR>
I'm really not sure what's going on, can anyone help me ?
Alex
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php