Jump to content

Few problems while creating webpage

- - - - -

  • Please log in to reply
8 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi , i want to be able to set css property of height to 500px by using php variable. Here's my contentAreaStyle.php file:
<?php header(“Content-type: text/css”); ?>
.contentAreaStyle{
    position: absolute;
    left: 208px;
    top: 199px;
    border-radius: 25px;
    -moz-border-radius: 25px;
    background-color: #B6BEB6;
    width: 596px;
    height: <?=$contentAreaHeight?>;
}
and this is my php code that is in the webpage file:
<?php include('templateContent.php');
        $contentAreaHeight = 500;
 ?>  
Something is wrong here because whole style file is not applied (i referenced it correctly)

I WOULD BE GRATEFUL IF SOMEONE COULD HELP ME TO SOLVE THESE PROBLEMS

Edited by thatsme, 28 May 2011 - 06:47 AM.


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Imagine the include() call will replace itself with the contents of the file templateContent.php, you could see how defining contentAreaHeight afterwards will do no effect.

Also, you must realize that include() will place the contents in to the current file and as such you must place them in HTML <style> tags.
<style>
  <?php 
     $contentAreaHeight = 500; 
     include('templateContent.php');
  ?>
</style>
You could as well reference to the source, using something such as $_GET parameters if you do not wish to use those tags:
<?php $contentAreaHeight = 500; ?>
<link rel="stylesheet" type="text/css" href="templateContent.php?contentareaheight=<?= $contentAreaHeight ?>" />
You would be wise to use is_int() on the $_GET['contentareaheight'] to prevent any nonsense input and display a default value if it is not a number.

As for the CSS question you could post it in our CSS forum, it is a little hard to answer that (I do not have much experience with CSS for example.)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
It's quite strange. In many tutorials i have seen that include doesn't have to be exactly between style tags. Maybe you thought that templateContent.php is my style file but is is not. Moreover, as far as i know, importing of style files also doesn't have to be exactly beetween style tags. When I put include('templateContent.php'); in the head section between style tags my whole webpage layout became messed up. Here's more of my code:
main php file

<html lang="lt">

    <?php include('head.php') ?>
        
    <body>
            <?php $contentAreaHeight = 500;
            include('templateContent.php');?>
    </body>
</html>

templateContent.php
<?php
    include('header.php');
    include('advertisementsArea.php');
    include('menu.php');
    include('contentArea.php');
?>
head.php
<head>
    <title>Green Death Vilnius</title>
    <link rel="stylesheet" type="text/css" href="styles/sideStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/buttonStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/headerStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/linkStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/regularFontStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/contentColor.css"/>
    <link rel="stylesheet" type="text/css" href="styles/messageStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/templateBackgroundStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/paragraphStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/paragraphHeaderStyle.css"/>
    <link rel="stylesheet" type="text/css" href="styles/contentAreaStyle.php" media="screen"/>
</head>
and contentAreaStyle.php
<?php header(“Content-type: text/css”); ?>
.contentAreaStyle{
    position: absolute;
    left: 208px;
    top: 199px;
    border-radius: 25px;
    -moz-border-radius: 25px;
    background-color: #B6BEB6;
    width: 596px;
    height: <?=$contentAreaHeight?>;
}


#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Ah that is better, It is easier to visualize the problem with more code.

Your postings seem consistent on the fact that you use incorrect quotes:
<?php header(“Content-type: text/css”); ?>
Those quotes are called smart quotes and are read by PHP as a parsing error.

If you view contentAreaStyle.php with your browser it will likely only display a PHP error - thus displaying none of your intended CSS. You can remove the header line completely, as the browser does not require the script to be sent as css related text (browsers are very simple with that.)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Now style file is aplied but only when i set height property in contentAreaStyle.php file (example height: 500px), but it fails to set value of height via php variable like i am trying to do (height: <?=$contentAreaHeight?>))

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You have the issue that the client is retrieving the file separately, with the <link> tag. You could pass a variable through $_GET:

    <link rel="stylesheet" type="text/css" href="styles/contentAreaStyle.php?height=<?=$contentAreaHeight?>" media="screen"/>

And then in that file you must retrieve the value from $_GET['height'] and not $contentAreaHeight.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Now my contentAreaStyle.php file is:
<?php header('Content-type: text/css'); ?> 
.contentAreaStyle{     
position: absolute;     
left: 208px;     
top: 199px;     
border-radius: 25px;     
-moz-border-radius: 25px;     
background-color: #B6BEB6;     
width: 596px;     
height: <?=$_GET['height']?>; 
}
and head.php file is:
<head>     
<title>green</title>       
 <link rel="stylesheet" type="text/css" href="styles/sideStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/buttonStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/headerStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/linkStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/regularFontStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/contentColor.css"/>     
<link rel="stylesheet" type="text/css" href="styles/messageStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/templateBackgroundStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/paragraphStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/paragraphHeaderStyle.css"/>     
<link rel="stylesheet" type="text/css" href="styles/contentAreaStyle.php?height=<?=$contentAreaHeight?>" media="screen"/> </head>
but it still does not work

#8
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Can you view the source code in your browser, and tell me if the height is properly set on the style sheet?

Can you then browse contentAreaStyle.php?height=... in your browser and tell me if the values are correct?

Remember, you must define $contentAreaHeight before head.php is included (or at the top if it.), I am unsure from your previous code if that is what you are doing. Viewing the pages in your browser and viewing the source will show if it does indeed place the value inside the CSS or does not.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#9
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
I needed to use <?php echo $contentAreaHeight?> instead of <?=$contentAreaHeight?>. Now value is asigned to property




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users