简体   繁体   中英

How do I use CSS inside a PHP While Loop to display data?

I already have the CSS Layout in a .css file.

Here is my php line of code

$display_block .= "<div id=\"contentTitle\">$title</div> <div id=\"contentDescription\">$description</div>"

echo $display_block;

For some reason, it isn't recognizing the "id" part of my code so my text is not being formatted!

I figured it out! It turns out it was my CSS code actually! And the reason I am putting the "id" in the php code is because I am displaying a data report onto a webpage with a loop.

why dont you write like this it is easy to undestand.....

$title='aaa';
$description = '222';
$display_block = "<div id='contentTitle'>".$title."</div> <div id='contentDescription'>".$description."</div>";
echo $display_block;

output

<div id='contentTitle'>aaa</div> <div id='contentDescription'>222</div>

Seems no wrong things of you code but,

Why you do not write like this:

<div id="contentTitle"><?php echo $title ?></div>

please try this code if your css id =contentTitle, if your css id =contentDescription than this code run

$display_block .= "<div id='contentTitle'>$title</div> <div id='contentDescription'>$description</div>";
echo $display_block;

best of luck dear

You can write like this- $display_block .= "$title $description"

echo $display_block;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM