...

View Full Version : How to style PHP echo result



jchrisphonte
01-24-2012, 12:19 AM
Hello All,

I have this code yet i would like to choose the text style for each element individually - Any help would be greatly appreciated.


echo $event.'<br> '.$company.' - '.$location.', '.$city.'<br>'.$month.'/'.$day.'/'.$year.'<br><hr />';

BluePanther
01-24-2012, 12:24 AM
Hello All,

I have this code yet i would like to choose the text style for each element individually - Any help would be greatly appreciated.


echo $event.'<br> '.$company.' - '.$location.', '.$city.'<br>'.$month.'/'.$day.'/'.$year.'<br><hr />';

Concatenate a span tag around each element, with a class or a style attribute.

jchrisphonte
01-24-2012, 02:51 AM
Hey BP,

As you may have noticed I am quite new to coding --- can you give me an example of concatenating if you have a moment?

BluePanther
01-24-2012, 03:03 AM
Hey BP,

As you may have noticed I am quite new to coding --- can you give me an example of concatenating if you have a moment?

Concatenation is the appending, or prepending depending on how you look at life, of one string on another. The bit of code you posted is concatenating strings - the . is PHP's way of concatenating strings.

So,


$string = 'thing';
$new_string = 'some'.$string; // $new_string is now 'something'

jchrisphonte
01-24-2012, 03:19 AM
Thank you for this -- It does make sense and I remember this from the PHP videos i've seen on assigning variables.

excuse me if this is logical for some --- how would i concatenate a style tag into a php element.
Would it look like the below??


echo <div class="event">$event.</div>'<br> '.$company.' - '

and then include #event{} in CSS??

BluePanther
01-24-2012, 05:14 AM
Thank you for this -- It does make sense and I remember this from the PHP videos i've seen on assigning variables.

excuse me if this is logical for some --- how would i concatenate a style tag into a php element.
Would it look like the below??


echo <div class="event">$event.</div>'<br> '.$company.' - '

and then include #event{} in CSS??

Close


echo '<div class="event">'.$event.'</div><br/>'.$company.' - '...

HTML is different from PHP. PHP is server side, so it doesn't parse HTML - html needs to be in a string.

jchrisphonte
01-24-2012, 04:00 PM
Hi BP,

thank you for the reply -- i tried it our this morning and for some reason the style formatting isnt appearing...



if ($query_run = mysql_query($query)) {
while ($query_row = mysql_fetch_assoc($query_run) ) {
$event= $query_row ['event'];
$company= $query_row ['company'];
$location= $query_row ['location'];
$city= $query_row ['city'];
$month= $query_row ['month'];
$day= $query_row ['day'];
$year= $query_row ['year'];



echo '<div class="where">'.$event.'</div>'.$company.'<div class="date">'.$month.'/'.$day.'/'.$year.'</div>'.$location.', '.$city.'<br><hr />';

for some reason the "listing" formatting remains for all the above echo results even after i specify the where class in my div tag.
Code I entered into CSS:



#listing{
width:630px;
font-size: 16px;
font-weight: bold;
font-family: arial;
color:#73abca;
float: left;
-moz-box-flex:1;
-webkit-box-flex:1;
}
#where {
font-size: 14px;
font-family: arial;
}


can you see where I may have made an error??

Wanna
01-24-2012, 04:03 PM
Hi BP,

thank you for the reply -- i tried it our this morning and for some reason the style formatting isnt appearing...



if ($query_run = mysql_query($query)) {
while ($query_row = mysql_fetch_assoc($query_run) ) {
$event= $query_row ['event'];
$company= $query_row ['company'];
$location= $query_row ['location'];
$city= $query_row ['city'];
$month= $query_row ['month'];
$day= $query_row ['day'];
$year= $query_row ['year'];



echo '<div class="where">'.$event.'</div>'.$company.'<div class="date">'.$month.'/'.$day.'/'.$year.'</div>'.$location.', '.$city.'<br><hr />';

Code I entered into CSS:



#listing{
width:630px;
font-size: 16px;
font-weight: bold;
font-family: arial;
color:#73abca;
float: left;
-moz-box-flex:1;
-webkit-box-flex:1;
}
#where {
font-size: 14px;
font-family: arial;
}


can you see where I may have made an error??

In CSS an # is for ID's
Change it to a . (#where is going to change to .where) and it should work

jchrisphonte
01-24-2012, 04:23 PM
worked!! thanks for the tip - I went back through my CSS and found why it was driving me crazy :)

jchrisphonte
01-24-2012, 04:37 PM
quick question...

I understand the . and # now

what are the cases when the id or class is just listed without the above as i have below?

where{

}

Inigoesdr
01-24-2012, 04:43 PM
quick question...

I understand the . and # now

what are the cases when the id or class is just listed without the above as i have below?

where{

}

That is used for HTML elements. Like:

textarea { width: 100%; }



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum