Jump to content

Formatting returned results using HTML/CSS


mattyd
 Share

Recommended Posts

Hello.  I am interested in taking a result returned from a database and having it displayed in a certain way/style on the user's screen; For example, the user enters text into a field and hits "submit" - the data is saved in the database then displayed to the user (This part I have working just fine so far due to help I received here.)

 

My question is if I would like to, for example, have said text not simply dumped to the top of the screen, inline, but nicely formatted in a boxed, text area, I assume I will use HTML/CSS, and I was wondering if anyone had any good links/tutorials regarding this topic so I may look further into it (my search thus far has not turned up the correct topic or results).

 

Thank-you in advance for any assistance.

~Matty

Link to comment
Share on other sites

you can integrate PHP into HTML/CSS very easily. here is the content of a file called test.php as an example

 

<html>
<head></head>
<body>
<p>The current second is <span style='font-size:16px;font-weight:bold;color:red;'><?php echo time(); ?></span> on this computer.</p>
</body>
</html>

Link to comment
Share on other sites

Hello.  I am interested in taking a result returned from a database and having it displayed in a certain way/style on the user's screen; For example, the user enters text into a field and hits "submit" - the data is saved in the database then displayed to the user (This part I have working just fine so far due to help I received here.)

 

My question is if I would like to, for example, have said text not simply dumped to the top of the screen, inline, but nicely formatted in a boxed, text area, I assume I will use HTML/CSS, and I was wondering if anyone had any good links/tutorials regarding this topic so I may look further into it (my search thus far has not turned up the correct topic or results).

 

Thank-you in advance for any assistance.

~Matty

 

I could really recommend to set a class or id with php and use an external stylesheet (instead of what i see very often here in-line style). that way you keep things nicely separated and it's easy to switch styles. But if you rather have in-line style (which sneaky let's you duplicate your code more) the result (view) will be the same

for instance a day and night concept:

 

css file could look like this:

.night {
color: white;
background-color: black;
}
.day{
color: blue;
background-color:white;
}

 

php code could look like this

$time = 'day'; //don't use this of course as a time indicator ;-)  
$my_array = array(2,4,6,8,10); // just a random array to created some output

if ($time == 'day'){ // in case it's day
  foreach($my_array as $key => $value){
    echo '<p class="day">any thing you like can be put inside here ('.$value.')(day) <p>';
}
}else{ // in case of night
    foreach($my_array as $key => $value){
    echo '<p class="night">any thing you like can be put inside here ('.$value.')(night) </p>';
}
}

 

I haven't tested it but I hope you see the Idea. if not let me know and ill try to clarify more.

::)

 

-edit: i just tested it and it works ::)

-edit2: changed the css a bit , they were the same. day now has a white background and blue font color, and night black background white font color

Link to comment
Share on other sites

notice though my code is a bit redundant, (i did that of course from a teacher perspective ::) lolzors)  it would have been better to set a class as variable, Like:

if ($time == 'lalala'){
  $class = 'day';
}else{
  $class = 'night';
}// and put this class var in your loop in the element tag or whatever you want.
// like
echo '<div class="'.$class.'"> lalalalalala </div>';

 

that way you only need 1 foreach()-loop instead of 2. Idea of css html and php stays the same though.

 

Nice thing too is that you can sell this to your client in case they have a special event. just make a nice css for it and php does the rest.

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

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