Styling PHP Output with a CSS file [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How do I attach a style sheet to PHP output? Besides bold and italic, it would be nice to give my output some style.
while ($row = sqlsrv_fetch_array ($query))
{
echo '<b>'.'School Name: '.'</b>'.$row['School_Name'].'<br />';
echo '<b>'.'CoSer Code: '.'</b>'.$row['COSER_Code'].'<br />';
echo '<b>'.'Product: '.'</b>'.$row['Product_Name'].'<br />';
echo '<b>'.'Cost Description: '.'</b>'.$row['Cost_Description'].'<br />';
echo '<br />';
}

Simply add <style> style code here </style> or
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<?php
//your code here
?>
At the top of the PHP page to use CSS.

Use this for your output:
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/CSSfile.css">
</head>
<body>
<?php //Put Here your code
?>
</body>
</html>
Give your output ids and classes which you can than style in your css.
For example you could give your <b> tags another text font with this css code:
b { font-family:Helvetica,sans-serif; }
For more information about changing fonts look here http://de.selfhtml.org/css/formate/zentrale.htm

Related

Require/Include in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I need some help, I have 2 php files and when I am calling some functions it tells me that
Fatal error: Call to undefined function get_contents() in /home/f77inq/public_html/php/shares.php on line 13
eventhough in the files from where I call the functions I have typed require("name ofmy file");
shares.php
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
adad
<?php
$data = get_contents();
print_contents($data);
?>
</body>
</html>
This is the file from where I am calling the functions.
<?php
require("../../php_include/services.php");
require("../../php_include/query.php");
putenv("ORACLE_HOME=/oracle/product/12.1.0/dbhome_1");
function get_contents() {
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
function print_contents($contents) {
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
</tr>
<?php
foreach ($contents['shares'] as $share) {
print "<tr>";
//****** LINKS TO EVERY
$identifier = urlencode($share['COMPANY']);
print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";
print "</tr>";
}
?>
</table>
<?php
}
require ("shares.php"); //<<<<<<<<<<<<<<<<<<<<<<
?>
As you can see down bellow I require the shares php file.
Both files are located in the same folder
for testing i put this code in a file named like.php-
<?php
function get_contents() {
echo "Got it";
}
require ("shares.php");
?>
and in the shares.php file i used this-
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
<?php
$data = get_contents();
echo $data;
?>
</body>
</html>
it works perfectly without eny error.
The error you show is from a file shares.php, yet the file you require is share.php. This error is likely happening somewhere else in the process since all of the code you've shown is valid and certainly works.

Using PHP to change HTML elements [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a simple HTML page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p id="demo">Nothing here</p>
<button onclick="?">Button</button>
</body>
</html>
and a separate PHP file:
<?php
// Load and exec craigslist
$site = curl_init("https://www.craigslist.org/about/sites");
curl_setopt($site, CURLOPT_RETURNTRANSFER, true);
$target = curl_exec($site);
$dom = new DOMDocument();
#$dom -> loadHTML($target);
// Save logo text
$title = $dom -> getElementById('logo') -> nodeValue;
?>
Here's what I want to do:
When I click the button on the HTML page, I want the PHP script to run so that I can get the craigslist title and store it a PHP variable ($title). I want to replace the text in <p id="demo> ("Nothing here") with the text stored in $title ("craigslist").
How do I do this?
Change your html to this
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<p id="demo">Nothing here</p>
<button onclick="myFunc()">Button</button>
<script>
function myFunc() {
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("demo").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","file.php",true); //Change file.php to the location of your php file
xmlhttp.send();
}
</script>
</body>
</html>
And add this line to your PHP file after setting the title variable
echo $title;
Now of course best case scenario you would use jQuery's built-in AJAX but this works well enough

tables are not aligning to the top of the page [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
my code:
achieved with the following code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
echo '<table><tr>';
$folders = #scandir('Users');
foreach($folders as $item):
if ((substr($item, 0, 1) == '.') || (preg_match("/\.php$/", $item)))
continue;
?>
<td>
<table width="220" border="1" valign="top">
<tr><th width="210" valign="top"><?php echo $item;?></th></tr>
<?php
if (is_dir("Users/$item"))
$target_folders = #scandir("Users/$item/uploaded/");
foreach($target_folders as $target_item){
if ((!preg_match("/^[.]/",$target_item)) || (!is_dir("Users/$item/uploaded/$target_item"))){
if ((substr($target_item, 0, 1) == '.'))
continue;
?><tr><td><?php echo $target_item ;?></td></tr><?php
}
}
?>
</table>
</td>
<?php
endforeach;
echo '</tr></table>';
?>
</body>
</html>
Now for the life of me i cant get the data that is displayed to align to the top of the page. i really don't know what i am doing wrong here but i do know that it is probably something simple.
a link to what i am displaying :
Current Code Outcome
add follownig in style sheet
td {
vertical-align: top;
}
regards
try
align td as top instead of table valign - top
posting since I wrote it anyway and then you changed the question content
present a jfiddle.net with actual rendered html,
explain why you are using such a complex doctype
try
http://jsfiddle.net/mplungjan/kG7B4/
td { vertical-align:top }

PHP index.php including structure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I need help. On my site I use URL parameters to decide which other PHP files to include on the page. My first question is: What should be in index.php and what should be in the included PHP file?
On the Internet I found instructions, suggesting this structure for index.php:
<html>
<head>
<?php include 'header.php'; ?>
</head>
<body>
<?php include 'menu.php'; ?>
<?php include 'content.php'; /* Including page based on the parameters in the url */ ?>
</body>
</html>
With this structure, how can I change the data in the <head> section based on the content in content.php? For example, for index.php?option=article&id_article=1, I will include article.php and show the article with id 1. How, then, can I change the <title>, <meta>, etc content when <head> was written before including the article?
Thanks!
One option that is kind of ugly but will work is instead of having header.php echo have it simply set variables like $title and $meta[]. Also instead of having article.php from echoing return a variable like $html. Also in article.php you can then overwrite any of the variables set in header.php. Then you can construct your index.php like so:
<?php include 'header.php'; ?>
<?php include 'article.php'; ?>
<html>
<head>
<?php echo $title ?>
</ head>
<body>
<?php include 'menu.php'; ?>
<?php echo $html ?>
</ body>
</ html>
Or you can look into ob_start() and ob_flush() etc...
To be as simple as possible, you could make your header a function, then call the function elsewhere...
Example (untested):
function drawHeader($title, $desc = "", $keywords = "", $extra = "") {
?>
<head>
<title><?php echo $title; ?></title>
<meta name="description" content="<?php echo $desc; ?>">
<meta name="keywords" content="<?php echo $keywords; ?>">
<link rel="stylesheet" type="text/css" href="path/to/my.css">
<?php echo $extra; ?>
</head>
<?php
}
The goal of the above would be so you could easily and quickly do something like...
<!DOCTYPE html>
<html>
<?php drawHeader("Home", "Some description", "Some, keywords, here"); ?>
<body>
<h1>Hello, world</h1>
<?php drawFooter(); // maybe a footer of some type? ?>
</body>
</html>
Or you could set the variables before calling the included file... and in the included file simply echo those values in the proper places.
There's tons of ways to do this, lots of standards and best practices, frameworks, templating systems, placeholders using output buffering, etc.
first the instructions you found have nothing to learn from
as second to get the content of the file article.php
using the url index.php?option=article&id_article=1
you will need to use the $_GET['id_article']
Example :
$page = $_GET {'id_article'};
if (isset($page)) {
$url = $page.".php";
if (file_exists($url)) {
include $url;
}
and you can use database for storing the articles and use the query then using
if ($_REQUEST['id_article'] == $page) {
$querythearticle = mysql_query("select tablename from database_name where id_article='$page'");
}

Generating XML which contains HTML in PHP - Problems with variables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am sitting on a little problem here:
I have a php file which generates xml data.
$requestXmlBody .= "<Version>$compatabilityLevel</Version>";
Now there are variables pulled from the upper php code and also HTML is generated
$requestXmlBody .=
'<Description>
<![CDATA[
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--some JS-->
</script>
<img src="http://www.myserver.com/pic.jpg" class="etalage_thumb_image" />
</body>
</html>
]]>
</Description>';
Now strangely I cannot mix variables and HTML Code.
As you can see I use CDATA for the HTML. I want to use a variable for the image name rather than a fixed link. So the code would look like this
$requestXmlBody .= '<Description>
<![CDATA[
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--some JS-->
</script>
<img src="$imagelink" class="etalage_thumb_image" />
</body>
</html>
]]>
</Description>';
But this just does not work. I tried this
$requestXmlBody .= '<Description>
<![CDATA[
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--some JS-->
</script>
<img src="]]>$imagelink<![CDATA[" class="etalage_thumb_image" />
</body>
</html>
]]>
</Description>';
But also this will not work. I even tried to hand over the php variable (which I grab from a session btw) to a JS variable and include it with document.write
Still no success.
This one would work
$requestXmlBody .= '<Description>
$imagelink
</Description>';
But not together with the generated HTML code as you can see above.
Any help is appreciated.
Thanks
Separate concerns. Don't do several things at once. If you split your embedded HTML into its own variable, it gets much easier.
As soon as you have 'freed' the HTML string from the XML context, you'll see that the problem still exists. It is caused by quoting the string with single quotes, which prevent interpolation. You have to use string concatenation instead of embedding the variable directly.
$description = '<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--some JS-->
</script>
<img src="' . $imagelink . '" class="etalage_thumb_image" />
</body>
</html>';
$requestXmlBody .= '<Description>
<![CDATA[' . $description . ']]>
</Description>';
Be sure that your HTML string does not contain a CDATA section itself, since CDATA sections cannot be nested.
The best approach will be to use the writeCData method.
$link= 'link goes here';
$imagelink = '<img src="'.$link.'" /> ';
// serve xml doc as xml
header('Content-type: application/xml');
// set up the document
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('description');
// CData output
$xml->writeCData($imagelink);
$xml->endElement();
// end the document and output
$xml->endElement();
echo $xml->outputMemory(true);

Categories