/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Massive str_replace on MySQL results

Hey, I’ve got this query and result from a mysql database:

$result = mysql_query(“SELECT * FROM stories WHERE showonpage=’$pageid’ and auth_lvl like ‘$auth_lvl’ and published=’1′ ORDER BY $sort $order”);

while ($row = mysql_fetch_array($result)) {
$postlist[] = array(
‘body’ => $row[‘body’],
‘title’ => $row[‘title’],
‘author’ => $row[‘author’],
‘date’ => $row[‘date’],
‘time’ => $row[‘time’],
‘icon’ => $row[‘icon’],
‘details’ => $row[‘showdetails’]
);

[B]And then I got something like this[/B]:

$result = Mysql_query (“SELECT * from glossary”);
$num = mysql_num_rows($result);
$i = 0;

while ($i < $num){

$target = mysql_result( $result,$i,’target’);
$title = mysql_result( $result,$i,’title’);
$anchor = mysql_result( $result,$i,’anchor’);

$postlist[‘body’] = str_replace(“$target”, “<a href=”$glossary_page#$anchor”>$title</a>”, $postlist[‘body’]);

$i++;
}

Basically what should happen is this: First all posts are pulled from the database, then all glossary entries should be pulled from another table. When this is done, all words that are in the postbody that are also in the glossary table should be replaced by a link that has the $title and $anchor from the glossary table.

This script however doesn’t seem to work, do any of you know how to get it working?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@IcelineauthorDec 14.2006 — Nevermind, I did it otherwise and got it to work!
×

Success!

Help @Iceline spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...