ok, i'm not quite certain the order of things. where is the originall list coming from?
Quote:
Exercise A name
Exercise A description..... See also Exercise B Name.
|
all of this information should be in the db.. there won't be a need to go back and replace names with id's otherwise.
but if you cannot make the necessary changes, you can use a regular expression to find and replace names w/ links. i would look into 'preg_replace()'
something like this:
Code:
$str_of_excercises = "Exercise A name \n Exercise A description..... See also Exercise B Name";
while ($row = mysql_fetch_array($rs))
{
preg_replace(
"/". $row["name"] ."/ig" ,
"<a href=\"excercises.php?id=". $row["id"] ."\">". $row["name"] ."</a>" ,
$str_of_excercises
);
)
echo $str_of_excercies;
be carefull for duplicate replaces with this method...
personally, I would store all this in the db w/ the related links and have a nice and easy loop w/ xhtml structure... something like this
Code:
$rs = mysql_query("SELECT * FROM excercises ORDER BY name");
while ($row = mysql_fetch_array($rs))
{
echo "<div class=\"excercise\">\n";
echo "<h1 class=\"title\">". $row["name"] ."</h1>\n";
echo "<p class=\"description\">". $row["description"] ."</p>\n";
echo "<div class=\"related_links\">";
$rsRelated = mysql_query("SELECT * FROM related_excercises WHERE idExcercise = ". $row["id"] ." ORDER BY name");
if (@mysql_num_rows($rsRelated) > 0)
{
echo "See also, ";
while ($row2 = mysql_fetch_array($rs))
echo "<a href=\"excercise.php?id=". $row2["idExcercise"] ."\">". $row2["name"] ."</a>\n";
echo "</div>\n";
}
echo "</div>\n";
}
Last edited by createvibe.com; 07-02-2006 at 05:14 PM..
|