Reputation: 306
Here in a.php file only 1 row is getting displayed.I used fetch(PDO::FETCH_ASSOC) stll i didnt get whole of the rows from chatlog. where is the problem?
a.php
<html>
<head>
</head>
<body>
<?php
Include ('connect.php');
$query = $handler->prepare("SELECT message FROM chatlog");
$query->execute();
while ($row = $query->fetch()) {
$message = $row['message'];
$query = $handler->prepare("SELECT * FROM smilies");
$query->execute();
while ($row = $query->fetch()) {
$emoji = $row['emoji'];
$smiley = "<img src='image/" . $row['smiley'] . "'/>";
$message = str_replace($emoji, $smiley, $message);
}
print_r("$message");
}
?>
</body>
</html>
Upvotes: 1
Views: 59
Reputation: 157917
<?php
Include ('connect.php');
$smileys = $handler->query("SELECT emoji, smiley FROM smilies")->fetchAll();
$query = $handler->query("SELECT message FROM chatlog");
foreach($query as $row)
{
$message = $row['message'];
foreach($smileys as $sm)
{
$smiley = "<img src='image/$sm[smiley]'/>";
$message = str_replace($sm['emoji'], $smiley, $message);
}
echo $message;
}
Upvotes: 1