Formatting tabs HTML PHP CSS - php

I've been away from programming in general for a long time. Amazing how you forget the simplest things. So I'm trying to warm-up my web design/PHP by making a resume generator.
I made my resume in Word, and I want to try to mimic the document formatting.
I tried doing this with tables, and then I scraped that because it wasn't working exactly like I wanted, and now I'm using divs and spans.
But that's breaking the formatting even more so I don't know what to do...
My main problem is getting spaces to line up precisely the way tabs do in Microsoft Word, on the same line as other things.
Here is the code I'm using
function fieldFill($fieldL, $fieldR = 'NoneAtAll'){
$numOfSpaces = 50;
echo '<div class="left">' . $fieldL . '</div>';
//if ($fieldR != 'NoneAtAll'){
// for($i = 0; $i <= $numOfSpaces - strlen($fieldL); $i++){
// echo '&nbsp';
// //echo $i;
if ($fieldR != 'NoneAtAll'){
for($i = 0; $i <= $numOfSpaces; $i++){
echo '&nbsp';
}
echo '<span class="rightt">' . $fieldR . '</span>';
echo '<br></br>';
}
}
And here is the CSS section
<style>
.rightt {margin: 0 0 0 300px;}
.name { font-size: 22pt;}
.sections {
padding: 15px 0px 0px 0px;
font-size: 12pt;
font-weight: bold;
text-decoration: underline;
}
.years {
font-size: 12pt;
font-weight: bold;
/*white-space:pre*/
}
.jobtits {
font-size: 12pt;
font-weight: bold;
}
</style>
I know there's already good resume generators out there but I'm doing this for the practice. Thanks
Here we go, I want to mimic this format
As of today I'm finding that this code
<div id="page-container">
<div id="leftside">
<div class="name">Name</div>
Address
<br>
City
<br>
State
<div class="sections">Objective</div>
To do good stuff!
<div class="sections">Education</div>
A college
<div class="sections">Awards</div>
Did some good stuff
<div class="sections">Job Experience</div>
<div class="jobtits">Some place</div>
Was an editor
<div class="jobtits">Another place</div>
Did stuff there too.
<div class="sections">Skills</div>
</div>
<div id="rightside">
<div class="name">That's my name</div>
Mobile: 334-223-3244
<br>
Home: 334-223-3244
<br>
Email: Email#me.com
<div class="sections">Filler</div>
Filler
<div class="sections">Filler</div>
2012-1030
<div class="sections">Filler</div>
Filler
<div class="sections">Job Experience</div>
<div class="jobtits">Jul 00 - 32</div>
Filler
<div class="jobtits">Everybody's heard</div>
About the bird.
<div class="sections">Skills</div>
</div>
</div>
is working for the most part, but there are still parts that need to overlap, such as the objective line. I probably need to make a new div/table for that huh? I'm walking through the html static before making it dynamic.

SPAN tag is inline element so margin will not be appled to it, use DIV tag instead.

Related

Display PHP While Loop Horizontally & Vertically Using Flexbox

Having a bit of an issue here. Could use some insight. I'm displaying user created events to visitors to my website. I'm using a while loop to display everything that hasn't not yet already passed. My goal is to display two separate events right next to each other, then another two below that and so on. Currently I'm using the flex box css property to achieve this, but it's only displaying the output vertically and not the way I want it to, meaning it's only putting one event per line. Here is my current output for displaying the events.
include 'db_connect.php';
$event_type = $_POST['event_type'];
$state = $_POST['state'];
$current_date = date("Y-m-d");
$sql = "SELECT * FROM events WHERE event_type LIKE '%".$event_type."%' AND state LIKE '%".$state."%' AND end_date > '$current_date' ORDER By end_date ASC";
$result = mysqli_query($conn, $sql);
if (isset($_POST['search-events']) && !empty($event_type) && !empty($state)) {
while($row = mysqli_fetch_array($result)) {
$event_name= $row['event_name'];
$image = $row['image'];
$start_date = $row['start_date'];
$end_date = $row['end_date'];
$start_time = $row['start_time'];
$end_time = $row['end_time'];
$street = $row['street'];
$city = $row['city'];
$state = $row['state'];
$zip_code = $row['zip_code'];
$id = $row['event_id'];
echo '<div class="filter-wrap">';
echo '<div id="filter-boxes">';
echo '<div id="list_image"><img src="'.$image.'"></div>';
echo '<div id="list_name">'.$event_name.'</div>';
echo '<div id="list_date">'.$start_date. ' - ' .$end_date. '</div>';
echo '<div id="list_time">' .$start_time. ' - ' .$end_time. '</div>';
echo '<div id="list_location">'.$street.''.$city.''.$state.''.$zip_code.'</div>';
echo '</div>';
echo '</div>';
}
}
Then there's the css that I'm using.
.filter-wrap {
display: flex;
flex-direction: row;
padding: 10px;
justify-content: center;
align-items: center;
}
#filter-boxes {
border: 2px solid #999;
text-align: center;
width: 50%;
height: 150px;
}
As you can see, I'm using the flex property inside the container that holds each of the individual boxes that holds each event. I have the flex direction set to row since I want it to display horizontally, then go the next line after it runs out of room on each line.
I tried a few things. I tried switching to the css column count property but didn't get the results I was expecting. I honestly probably didn't tweak with that property enough, but I have my heart set on the flex box property. I also tried setting the flex direction to column and also tried adding an inline-block display property to the boxes that are suppose to repeat on the while loop with each event. I'm finding this online that are kind of similar to my issue, but not quite. One uses javascript, but this can obviously also be accomplished somehow with php. I also found several articles talking about centering the content using flexbox, which is not the goal here.
Try move your .filter-wrap div element to outside of the while() {} loop.
Your current coding:
while() {
echo '<div class="filter-wrap">';
echo '<div id="filter-boxes">';
// content goes here...
echo '</div>';
echo '</div>';
}
will result in following structure where each .filter-wrap only container a single child .filter-boxes, which will always results in vertical presentation:
<div class="filter-wrap">
<div id="filter-boxes"> content </div>
</div>
<div class="filter-wrap">
<div id="filter-boxes"> content </div>
</div>
<div class="filter-wrap">
<div id="filter-boxes"> content </div>
</div>
For horizontal presentation, the correct structure should be one .filter-wrap consists of multiple .filter-boxes childs:
<div class="filter-wrap">
<div id="filter-boxes"> content </div>
<div id="filter-boxes"> content </div>
<div id="filter-boxes"> content </div>
</div>
So you can try change your coding to:
echo '<div class="filter-wrap">';
while() {
echo '<div id="filter-boxes">';
// content goes here...
echo '</div>';
}
echo '</div>';
Snippet for demo to you the coding logic result. It is in JS but you just have to apply the same in your PHP
Hope it helps and Happy coding!
var result_1 = document.getElementById('result_1');
var result_2 = document.getElementById('result_2');
var content_1 = '';
var content_2 = '';
content_2 = '<div class="filter-wrap">';
for (var i = 1; i <= 5; i++)
{
// result 1
content_1 += '<div class="filter-wrap"> <div class="filter-boxes">content ' + i + '</div> </div>';
// result 2
content_2 += '<div class="filter-boxes">content ' + i + '</div>';
}
content_2 += '</div>';
result_1.insertAdjacentHTML('beforeend', content_1);
result_2.insertAdjacentHTML('beforeend', content_2);
.filter-wrap {
display: flex;
flex-direction: row;
flex-wrap: wrap;
padding: 10px;
justify-content: center;
align-items: center;
}
.filter-boxes {
border: 2px solid #999;
text-align: center;
width: 50%;
height: 50px;
/* for two columns display */
max-width: 49%;
}
#result_1,
#result_2 {
background-color: lightgray;
border: 1px dashed black;
margin: 3px;
}
result 1
<div id="result_1"></div>
result 2
<div id="result_2"></div>

One header but with different banners for each page (php if)

I build my website for fun and want to put different banner on each page, in my header i have random banners who appear with this code,
<div style=' height:145px; background-image:url(images/banners/banner<?php
echo rand(1,3); ?>.jpg); background-position:center center; border-
radius:4px;'></div>
So there is 3 banners and each time i refresh random one appear, but i want to have another 3 banners for my other page but with the same include"inc/header.php", maybe 'if' statement could work but i really don't know how to do it.
Sorry for my English i'm french.
Assuming the three banners are in the same folder, the following would be a simple solution:
Place the banner code in a separate file:
banner.php
<div style=' height:145px; background-image:url(images/banners/banner<?php
echo rand($start,$end); ?>.jpg); background-position:center center; border-
radius:4px;'></div>
Then you can call it from your page:
$start = 4; //First banner number
$end = 6; //Last banner number
include('inc/banner.php');
This is not the most elegant solution, but it's a simple nice simple one for a novice programmer that introduces some concepts.
I found how to do it myself:
<?php if ($title == "page1"): ?>
<div style=' height:145px; background-image:url(images/banners/banner<?
php echo rand(1,6); ?>.jpg); background-position:center center; border-
radius:4px;'></div>
<?php elseif ($title == "page2"): ?>
<div style=' height:145px; background-image:url(images/banners/banner<?php
echo rand(7,9); ?>.jpg); background-position:center center; border-
radius:4px;'></div>
<?php endif; ?>
I just need to create new "elseif" for every page and assign new banners with the same header.php all over my website.
use if
example
if ($id == 1){
<div style=' height:145px; background-image:url(images/banners/banner<?
php
echo rand(1,3); ?>.jpg); background-position:center center;
border-
radius:4px;'></div>
}
if ($id == 2){
<div style=' height:145px; background-
image:url(images/banners/banner<?php
echo rand(1,3); ?>.jpg); background-position:center center; border-
radius:4px;'></div>
}
if ($id == 3){
echo "no banner";
}
help fixing this sh!t mod, thanks

How to properly display two strings side by side

I have two arrays which I use implode() on to convert into strings which are then echoed out.
Ideally i'd like the 1 value from the one string to be next to the other value in the other string, prefably nested inside a
<p></p>
Here's the code I'm using to issue a line break after every value, wrap it in a div, and float it.
<?php
echo '<div class="wrapper"><div style="text-align:left; float:left;"
class="glue">';
echo implode('<br>',$test);
echo '</div>';
echo '<div style="text-align:right; float:right;" class="glue">';
echo implode('<br>',$_POST);
echo '</div></div>';
?>
This works well for now as both divs sit next to each other within my container but it would be easier if the values were inside P tags instead so I could easily put an image in-between them.
I've added some images below to better demonstrate what I'm going for.
The first one is what I've tried and the second one is what I would like.
Is it what you want?
<style type="text/css">
p{
overflow: hidden;
}
span.left{
float: left;
}
span.right{
float: right;
}
</style>
<?php
foreach($test as $k=>$v){
echo '<p><span class="left">'.$test[$k].'</span><span class="right">'.$_POST[$k].'</span></p>';
}
That is not possible until you split the paragraph tag into 2 halves.
Try this,
.div1 {
float: left;
}
.div2 {
float:right;
}
.div2 {
float:right;
text-align: right;
}
<p>
<div class="div1">Left Text</div>
<div class="div2">Right Text</div>
</p>
if both arrays have the same length the most simple example woud look like this:
<?php
$test[0] = "a";
$test[1] = "b";
$test[2] = "c";
$test[3] = "d";
$test2[0] = 1;
$test2[1] = 2;
$test2[2] = 3;
$test2[3] = 4;
for($i=0;$i<count($test);$i++)
{
echo "<p><nobr>".$test[$i] . "</nobr> <nobr style='float:right;'>" . $test2[$i] . "</nobr></p>";
}
if you wanna test to see if it fits just paste the code here

get some words in html using simple_html_dom

I wanna get zumbai, n, and something from line of html below with simple_html_dom:
<p>
<div align="left" style="margin: 0.00mm 0.00mm ;">
<p style="font-family: Arial; font-size: 1.0em;">
<b>zumbai</b>
<i>n</i> something
</p>
</div>
here's my code :
foreach($html->find('div.align') as $tag1) {
foreach($tag1->parent()->find('p.style') as $tag2){
$words1 = $tag2->first_child();
$words11= $words1->plaintext;
$words2 = $tag2->first_child()->first_child();
$words22= $words2->plaintext;
}
}
but it doesn't works. thank you :)

How do I add CSS font styles to PHP echos?

How can I add different font-styles to different rows?
I want all of them to have a different font-style. For example:
while($row = mysqli_fetch_array($result))
{
echo $row['Nimi']."<br>".$row['Kirjailija']."<br>".$row['ISBN']."<br>".$row['Kunto']."<br>".$row['Hinta']."€"."<br>".$row['Pvm'];
echo "<br>"."<br>";
}
I am not so good at php. But I gave a little try about it like this:
Slight modification to your code.. Adding a classing to each row!
i = 1;
while($row = mysqli_fetch_array($result))
{
/* adding <span class="row1"> row2 etc.. using i */
echo "<span class='row".i."'>".$row['Nimi']."<br>".$row['Kirjailija']."<br>".$row['ISBN']."<br>".$row['Kunto']."<br>".$row['Hinta']."€"."<br>".$row['Pvm'];
echo "<br>"."<br></span>";
i++;
}
Giving Styles in css based on row names:
.row1{
font-family: verdana;
}
.row2{
font-family: arial;
}
etc..
I am repeating once again, I'm not sure about syntax.. I am posting this only to share the concept hoping that it should work! :)
For example:
style="font-family:verdana;"
You can use inline styling <span style="color: red;">test</span>, or use classes of css: <span class="red-color">text</span> with a css
.red-color{
color: red;
font-family: Arial;
}
In general, it is better to use classes with an external css file - that would keep your code organized and scalable.
In your case it is possible to use inline style like:
echo "<span style=\"color: red; font-family: Arial\">" . $row['Nimi'] . "</span>" . "<span style=\"color: green; font-family: Verdana\">" . $row['Kirjailija'];
Also, it is not a good practice to use <br /> now-a-days. Better wrap each text with a <span>, or a <div>

Categories