mattyd Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216297-formatting-returned-results-using-htmlcss/ Share on other sites More sharing options...
BlueSkyIS Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216297-formatting-returned-results-using-htmlcss/#findComment-1124098 Share on other sites More sharing options...
fortnox007 Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216297-formatting-returned-results-using-htmlcss/#findComment-1124154 Share on other sites More sharing options...
fortnox007 Posted October 19, 2010 Share Posted October 19, 2010 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 https://forums.phpfreaks.com/topic/216297-formatting-returned-results-using-htmlcss/#findComment-1124161 Share on other sites More sharing options...
mattyd Posted October 20, 2010 Author Share Posted October 20, 2010 Thanks for everyone's help and input. ~Matty Link to comment https://forums.phpfreaks.com/topic/216297-formatting-returned-results-using-htmlcss/#findComment-1124170 Share on other sites More sharing options...
fortnox007 Posted October 20, 2010 Share Posted October 20, 2010 mark it solved before its too late and the aliens abduct you! :o Link to comment https://forums.phpfreaks.com/topic/216297-formatting-returned-results-using-htmlcss/#findComment-1124175 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.