I\'m trying to style the output of each echo.
Ideally I\'d like to use
for each echo, but I\'m not too sure how to ach
I'd create a function that does this:
function decorated_echo($text) {
echo '<span class="myclass">' . $text . '</span>';
}
This way, you don't have to repeat this everytime you want this behaviour.
You are guessing right, just add required html in the echo:
echo '<span class="yourclass"><img src="'.$row['Image'].'" /></span>';
or you can just put inline style if no css file is loaded:
echo '<span style="color:red;"><img src="'.$row['Image'].'" /></span>';
$result = mysql_query("SELECT * FROM Blog");
while($row = mysql_fetch_array($result))
{
echo "<span class=\"myclass\">$row['Date']</span>";
echo "<span class=\"myclass\">$row['Title']</span>";
echo "<span class=\"myclass\">$row['Message']</span>";
echo "<img src='".$row['Image']."'/>";
}
mysql_close($con);
or, much nicer, in a table:
$result = mysql_query("SELECT * FROM Blog");
echo "<table>"
while($row = mysql_fetch_array($result)) {
echo "<tr>"
echo "<td>$row['Date']</td>";
echo "<td>$row['Title']</td>";
echo "<td>$row['Message']</td>";
echo "<td><img src='".$row['Image']."'/></td>";
echo "</tr>"
}
echo "</table>"
mysql_close($con);
You then can style each row and column with a class.
Try this:
$prepend = "<span class=''>";
$append = "</span>";
$result = mysql_query("SELECT * FROM Blog");
while($row = mysql_fetch_array($result))
{
echo $prepend.$row['Date'].$append;
echo $prepend.$row['Title'].$append;
echo $prepend. $row['Message'].$append;
echo $prepend."<img src='".$row['Image']."'/>".$append;
}
mysql_close($con);