Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts

    How to style PHP echo result

    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.

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

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jchrisphonte View Post
    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.

    PHP Code:
    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.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (01-24-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jchrisphonte View Post
    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,
    PHP Code:
    $string 'thing';
    $new_string 'some'.$string// $new_string is now 'something' 
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (01-24-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    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??

    PHP Code:
    echo <div class="event">$event.</div>'<br> '.$company.' - ' 
    and then include #event{} in CSS??

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jchrisphonte View Post
    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??

    PHP Code:
    echo <div class="event">$event.</div>'<br> '.$company.' - ' 
    and then include #event{} in CSS??
    Close
    PHP Code:
    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.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (01-24-2012)

  • #7
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    Hi BP,

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


    PHP Code:
    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:

    Code:
    #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??
    Last edited by jchrisphonte; 01-24-2012 at 03:04 PM.

  • #8
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Quote Originally Posted by jchrisphonte View Post
    Hi BP,

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


    PHP Code:
    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:

    Code:
    #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

  • Users who have thanked Wanna for this post:

    jchrisphonte (01-24-2012)

  • #9
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    worked!! thanks for the tip - I went back through my CSS and found why it was driving me crazy

  • #10
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    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{

    }

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by jchrisphonte View Post
    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:
    Code:
    textarea { width: 100%; }

  • Users who have thanked Inigoesdr for this post:

    jchrisphonte (01-24-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •