Jump to content

PHP and CSS - Best Practice


sparknlaunch

Recommended Posts

Hi,

 

(Apologies in advance if this is a total newbie question - if it is, just give me some idea on what I need to search for!)

 

I have written php code that essentially pulls together multiple records (using mySQL) and displays them in a webpage. The challenge I have now is making the output pretty.

 

What is the best way to do this?

 

I have my css file (with several styles in the format below):

.textstyle0 {font-family:Tahoma;font-weight:normal;font-style:normal;font-size:48px;text-decoration:none;color:#ffffff;}
div.Object50 { position:absolute; padding-right:5px; top:189px; left:92px; z-index:0; text-align:left; width:437px; }

 

And my html file (that I want to bring in the php output):

<div class="Object50"><span class="textstyle0">Q. THIS IS A TEST?<br></span></div>

 

My php code is sitting in a tidy block:

$result = mysql_query("SELECT * FROM tbl_scores WHERE ID=$f_id") or die(mysql_error()); 
$row = mysql_fetch_array( $result );
$f_score = $row['score'];
$f_freq = $row['freq'];
echo "test" . $f_score;

 

Do I need to update all my php code with the relevant css tags or can I reference the php? Or do I split up my php code?

 

Do I leave my php code at the top and store all the values somewhere? Then these get pulled into html?

 

I guess I am trying to reduce how much of the php coding I need to modify while leaving the flexibility in the design....

 

 

Link to comment
https://forums.phpfreaks.com/topic/259159-php-and-css-best-practice/
Share on other sites

I'm not quite sure if I'm following what you're asking, but since PHP is going to simply print text, you can style it as you normally would with HTML/CSS. 

 

For example: 

 

echo'<p id="someDiv">' . $f_score . '</p>';

 

You could also do something like this: 

 

<p id="someDiv"><?php echo $f_score ?></p>

 

Thanks for the reply.

 

I am looking for the easiest way to retain my php code in one place while adding in formatting. Your second suggestion looks best. This way I can run all processing code at top and simply bring in out put with html at bottom.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.