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
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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.