tables are not aligning to the top of the page [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 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 }

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 PDO to make a MySQL search query and display list of results

As the title suggests, I am trying to display a list of search results using PDO and MySQL...I have a table of recipes, which have recipe_id, name & description. I would like to have a search box which can find a key word IN the name or description, i.e. "salad" or "carrots", and return a list of all matching recipes by displaying only their names. Before I switched to using PDO, I had the following code which did exactly what I needed:
<?php
include ("dbconnect.php");
if (!isset($_POST['search'])) {
header("Location:index.php");
}
$search_sql="SELECT * FROM Recipe WHERE name LIKE '%".$_POST['search']."%' OR description LIKE '%".$_POST['search']."%'";
$search_query=mysql_query($search_sql);
if (mysql_num_rows($search_query)!=0) {
$search_rs=mysql_fetch_assoc($search_query); }
?>
<!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>
<h3>Search results</h3>
<?php
if (mysql_num_rows($search_query)!=0) {
do { ?>
<p><?php echo $search_rs['name']; ?></p>
<?php }
while ($search_rs=mysql_fetch_assoc($search_query));
}
else {
echo "No results found";
}
?>
</body>
</html>
However, I am having difficulties doing the same with PDO...I have come up with the following code so far, but I suspect I am doing it wrong and furthermore I do not know how to display the actual results...I would be very grateful if anyone can provide some assistance, and please excuse my insufficient knowledge on the matter, I am still a newbie.
<?php
include ("dbconnect.php");
if (!isset($_POST['search'])) {
header("Location:index.php");
}
// keep track post values
$name = "%".$_POST['search']."%";
$description = "%".$_POST['search']."%";
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql ='SELECT * FROM recipe WHERE name LIKE ? OR description LIKE ?';
$q = $pdo->prepare($sql);
$q->execute(array($name,$description));
$data = $q->fetchAll(PDO::FETCH_ASSOC);
Database::disconnect();
?>
<!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 charset="utf-8">
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
<title>Untitled Document</title>
</head>
<body>
<div class="container">
<div class="row">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Search Results</th>
</tr>
</thead>
<tbody>
<?php
if ($data != null) {
foreach($data as $row)
{
echo '<tr>';
echo '<td>'. $row['name'] . '</td>';
echo '</tr>';
}
}else
{
echo '<td>'. "No results found" .'</td>';
}?>
</tbody>
</table>
</div>
</div>
</body>
</html>
You need to put the % on your parameters:
// keep track post values
$name = "%".$_POST['search']."%";
$description = "%".$_POST['search']."%";
Note, this in general is going to perform horribly as starting your like with a % will kill any index you have on name or description. As you're data grows, you'll start to see the slowdown.
Instead, you can take a look at full text searching options: http://blog.marceloaltmann.com/en-using-the-mysql-fulltext-index-search-pt-utilizando-mysql-fulltext/

Table printing only when <table> tags outside of php tags

From everywhere I look and research it seems possible to also put the tags within your php code, but for some reason only when my tag is outside of php it works. I can't seem to figure out the issue with it. The reason I am trying to print inside is because I am trying to create a nested for loop. Currently I commented out the table tags outside of the php and have them printed in the php code. This currently does not work. Here is my code and thank you again.
<?php print( '<?xml version = "1.0" encoding = "utf-8"?>') ?>
<!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>User selection page</title>
</head>
<!-- <table border="1px"> -->
<!-- <tbody> -->
<?php
/*
Version 1.1: Instead of printing the teams in different cells we are going to print the
games in one row and we select the game itself to see if an upset will occur.
*/
require_once('Conference.php');
$loadGameClass = new Conference();
$loadGameClass->loadTeams(array("(1)Gonzaga vs (16)Southern U", "(8)Pittsburgh vs (9)Wichita St", "(5)Wisconsin vs (12)Ole Miss", "(4)Kansas st vs (13)Boise St", "(6)Arizona vs (11)Belmont", "(3)New Mexico vs (14) Harvard", "(7)Notre Dame vs (10)Iowa St", "(2)Ohio St vs (15) Iona"));
$teams = $loadGameClass->getTeams();
echo "<table border="1">";
for ($i = 0; $i < 8; $i++)
{
$highSeed = $teams[$i];
//$lowSeed = $teams[((2*8)-1)-$i];
echo "<tr><td>$highSeed</td>"; //<td>$lowSeed</td></tr>
}
echo "</table>";
?>
<!-- </tbody> -->
<!-- </table> -->
<body>
</body>
</html>
First issue is
echo "<table border="1">";
it should be
echo '<table border="1">';
then
echo "<tr><td>$highSeed</td>";
better way is
echo '<tr><td>'.$highSeed.'</td></tr>';

Styling PHP Output with a CSS file [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
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

How can I use "PHP Simple HTML DOM Parser" to get the contents of an <h1></h1> tag?

I'm new to PHP =) Right now I am using PHP includes for my site template. I have my header, containing all my <head></head> info. What I want to do is write a code that will take the contents of the <h1></h1> tag from the page, and echo it into the <title></title> tag in my header.php include.
I got the PHP Simple HTML DOM Parser from here: [http://simplehtmldom.sourceforge.net/][1], and I found a code (I forget where in all my googling) that goes like this:
<?php
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$html = file_get_html('http://www.myurl.com/');
foreach($html->find('#content h1') as $element){
echo $element->plaintext;}
?>
That I think is supposed to echo the h1 tag contents? Like I said, I'm new to PHP and I only know the basics, and I don't know really know any OOP (yet), so I'm sorry if I'm asking a dumb question.
It looks like it's getting the current page, then putting the contents of the h1 tag into the variable $element, and then echoing it. But nothing happens when I put it into my page. Can anyone help me with what I'm doing wrong? Thank you for reading!! =)
EDIT: Here's my HTML
From the header.php file:
<!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" />
<?php
/* current page url */
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
<?php include '/home/dreami14/public_html/simplehtmldom/simplehtmldom/simple_html_dom.php' ?>
<title>
<?php
$url = curPageURL();
$html = file_get_html($url);
foreach($html->find('#main h1') as $element){
echo $element->plaintext;}
?></title>
<link rel="stylesheet" type="text/css" href="/stylesheet.css" />
</head>
<body>
From test.php:
<?php include '/home/dreami14/public_html/design/includes/head.php' ?>
<div id="main">
<h1>This should be the title</h1>
<p>Blah blah</p>
</div>
</body>
</html>
I don't get any errors, but my <title></title> is empty.
Edit to add: also, I echoed $url in the document itself so I know that part is working
You're not saying how your HTML is structured, but if you want to find the h1 with the ID content you need to use
foreach($html->find('h1#content') as $element){
the way you are doing it right now, it says "find any h1 element within another element with the ID content".
I would restructure your code a little. Basically, you are trying to get the content in h1 before it is populated. In your test.php I would define an array with meta data and then include the header.
Like so:
test.php
<?php
$meta = array();
$meta['title'] = "This should be the title";
include '/home/dreami14/public_html/design/includes/head.php'
?>
<div id="main">
<h1><?php echo $meta['title'] ?></h1>
<p>Blah blah</p>
</div>
</body>
</html>
head.php:
<!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>
<?php echo (isset($meta) && isset($meta['title'])) ? $meta['title'] : "Default title"; ?>
</title>
<link rel="stylesheet" type="text/css" href="/stylesheet.css" />
</head>
<body>
But if you start to do more complicated stuff, you should have a look at the Model-View-Controller design pattern and e.g. the Zend framework, which implements it.
I thinks it's the way, only print child content:
html = file_get_html($url);
foreach($ret->children as $child) {
echo $child;
}

Categories