This is head file of my program:
<?php
$obrazki = array('opona1.jpg', 'olej1.jpg', 'swieca_zaplonowa1.jpg',
'drzwi1.jpg', 'kierownica1.jpg',
'termostat1.jpg', 'wycieraczka1.jpg',
'uszczelka1.jpg', 'hamulec1.jpg');
shuffle($obrazki);
?>
<html>
<head>
<title>Czesci samochodowe Janka </title>
</head>
<body>
</br>
<h1 style="color:blue;font-size: 4em; text-align:center"> Czesci samochodowe Janka</h1>
</br>
<h3 style="color:red;font-size: 2em; text-align:center"> Witamy na stronie Czesci samochodowe Janka!</h3>
<form action="glowna.php" method=post>
<div align="center">
<table width = 100%>
<tr>
<?php
for ($i = 0; $i < 4; $i++) {
echo "<td align=\"center\"><img src=\"";
echo $obrazki[$i];
echo "\"/></td>";
}
?>
</tr>
<table>
</br>
<p style="color:red;font-weight:bold; text-align:center"> Prosimy o poswiecenie czasu i poznanie nas!</p>
</br>
<tr>
<td align="center"><input type="submit" value=" Wejscie "></td>
</tr>
</div>
</form>
</body>
</html>
File got extention *.php. It has to load some pics(opona1.jpg...) from $obrazki and if button "Wejscie" is pressed, programm in file glowna.php is called. Two problems:
1. If i try to change top of the program in such way
<html>
<?php
$obrazki = array('opona1.jpg', 'olej1.jpg', 'swieca_zaplonowa1.jpg',
'drzwi1.jpg', 'kierownica1.jpg',
'termostat1.jpg', 'wycieraczka1.jpg',
'uszczelka1.jpg', 'hamulec1.jpg');
shuffle($obrazki);
?>
and to change extetion of head file from *.php to *.html - program doesn't work properly and doesn't show images at all?
2.All image files from $obrazki were of different images and had different names without 1s( like opona.jpg, olej.jpg, swieca_zaplonowa.jpg etc.)from the very begining. But if I tried to insert different images in my program and give them the same names (opona.jpg, olej.jpg, swieca_zaplonowa.jpg...) program started to show old(previous) pix even if i erased them totally. But when i changed names of all images from $obrazki adding 1s to names(like u see now) program started to show these new images.Why have I to do like that? Is this means html save information about image files somewhere? Thnx
First, always try to use English words (like variables or files) in your code. It's easier to understand for readers which don't know your language.
You can't change file extension from PHP to HTML. Only PHP files can execute PHP scripts. (Of course, you can configure your server to execute HTML file as PHP or add rule to htacess to swap extension from .php to .html)
I think it's cache. You should always refresh page few times or use any method to clean cache after making changes (In chrome you can disable cache on the selected page)
Related
I'm trying to solve this current problem which I could use some help with:
From the database using php, the page must load an X number of sections, every section has some content on top, a table and some content on the bottom, the table can have 0 to any number of rows, depending on what was previously in the database.
Aside from the table the rest of the content doesn't vary in size.
I cannot know beforehand what will be the size of each section because of the table, and there is usually at least 30 sections.
This page must be print friendly, and aside from the page-breaks everything is already working.
I need to find a way to dynamically add page-breaks to fit the sections into the page without cutting them between pages.
The code is about 400 lines so it wouldn't be practical to post it here, but the section structure is something like this:
<section class="row">
<section>
<section class="col-md-2"></section>
<section class="col-md-8 printcenter">
<p class="docenteheader" >
<span class="tabspaceright">NAME: <strong>name</strong></span>
<span class="tabspaceleft">ID: <strong>number</strong></span>
</p>
<table>
<tr>
<th><strong>1:</strong></th>
<th><strong>2:</strong></th>
<th><strong>3:</strong></th>
<th><strong>4:</strong></th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
<p><strong>Something1:</strong> Something</p>
<p>
<span><strong>Something2: number</strong></span>
<span ><strong>Something3: number</strong></span>
</p>
<section class="rel_endline"></section>
</section>
<section class="col-md-2"></section>
</section>
</section>
I removed the css classes and original names and PHP code to facilitate viewing
Here is sample PHP code, let me know if anything is unclear. I tried to use self-explaining variable names.
<?php
$PAGEBREAK_LENGTH = 1000; // Add a page break every 1000 characters.
$lengthTracker = '';
while ($row = odbc_fetch_array($res)){
$lengthTracker .= $row['article'];
$lengthSize = strlen($lengthTracker);
if ($lengthSize > $PAGEBREAK_LENGTH) {
echo '<div class="page-break">This is a page break</div>';
$lengthTracker = ''; // Reset length tracker since we just added a break
}
echo '<div class="article">';
echo $row['article'];
echo '</div>';
}
?>
If you include the if ($lengthSize > $PAGEBREAK_LENGTH) before echoing the article, you will tend to include page-breaks "more often." If you include the if statement after the article is echod, you will have page-breaks less often (so you'd have potentially bigger blocks of text).
Experiment with both ways to see which style you prefer, since you (presumably) can't include page breaks mid-article.
I found out that my problem was caused not by the faulty page breaks, but I had negative margins in an element, that messed the entire way page breaks work, by removing that, it worked normally.
I'm using ACE Editor for a website which has been developed by Codeigniter framework. The problem is that after submitting the form, some tags attributes stripped.
HTML:
<form enctype="multipart/form-data" method="post" action="<?php echo site_url( 'admin/slider/populateFile')?>">
<div id="e1" style="display: none;">
<?php if(isset($sliderHTML)) { echo $sliderHTML; } ?>
</div>
<textarea class=" form-control" id="editorTextarea" name="sliderHTML" type="text" rows='20' wrap="off">
<?php if(isset($sliderHTML)) { echo $sliderHTML; } ?>
</textarea>
<pre id="editor"></pre>
</form>
PHP:
function populateFile()
{
$sliderHTML = $this->input->post('sliderHTML');
//echo $sliderHTML;
$filePath = 'application/views/admin/slider/sliderHTML.txt';
write_file($filePath, $sliderHTML, 'w');
redirect('admin/slider', 'location');
}
This is an example of what I'm trying to write in the code editor:
<img class="ls-l" style="top:195px;left:50%;white-space:nowrap;" data-ls="offsetxin:0;delayin:1720;easingin:easeInOutQuart;scalexin:0.7;scaleyin:0.7;offsetxout:-800;durationout:1000;" src="http://localhost:8080/afa/application/views/images/upload/slider/4978d-s1.jpg" alt="">
<p class="ls-l" style="top:150px;left:116px;font-weight: 300;height:40px;padding-right:10px;padding-left:10px;font-size:30px;line-height:37px;color:#ffffff;background:#82d10c;border-radius:3px;white-space:nowrap;" data-ls="offsetxin:0;durationin:2000;delayin:1500;easingin:easeOutElastic;rotatexin:-90;transformoriginin:50% top 0;offsetxout:-200;durationout:1000;">
FEATURES
</p>
But, the output will be like:
<img class="ls-l" data-ls="offsetxin:0;delayin:1720;easingin:easeInOutQuart;scalexin:0.7;scaleyin:0.7;offsetxout:-800;durationout:1000;" src="http://localhost:8080/afa/application/views/images/upload/slider/4978d-s1.jpg" alt="">
<p class="ls-l" 300;height:40px;padding-right:10px;padding-left:10px;font-size:30px;line-height:37px;color:#ffffff;background:#82d10c;border-radius:3px;white-space:nowrap;" data-ls="offsetxin:0;durationin:2000;delayin:1500;easingin:easeOutElastic;rotatexin:-90;transformoriginin:50% top 0;offsetxout:-200;durationout:1000;">
FEATURES
</p>
Notice that style attribute of img has been stripped, and this happens also for <p> but it stops on the space after font-weight:. I don't know why.
Any Ideas?
EDIT: Finally, I knew that this has nothing to do with the code editor. The problem was with xss_filtering in Codeigniter and this answer works for me. :)
I am not familiar with Ace in particular (i like Wysihtml5), but I think they have something in common.
Wysihtml5 strips html (you can select which). It makes sure the html output is clean.
In short, it's a function and apparently style is not permitted. You should permit that (if it has the option to)
You should escape value of $sliderHTML with htmlspecialchars before adding it to the document, otherwise it will create actual tags and break your page.
try putting "</textarea><script>alert('all your passwords belong to us')</script>" in place of $sliderHTML
So I was just wondering if it was considered bad practice to open and close PHP statements, and let me explain what I mean. I know I can make variables at the beginning of my code but I like to group stuff together.I'm not sure if making one big PHP statement with all my variables is better / worse / same as opening and closing PHP statements similar to the example below.
<html>
<head></head> <---- HTML STUFF
<?php
(php stuff where connection to mysql db goes and other variables and errors)
?>
<body>
<html> <----- HTML stuff
<?php
(php stuff to call a specific table from DB)
?>
<html> <----- HTML stuff
<?php
(php stuff to call a specific table from DB)
?>
<html> <----- HTML stuff
<?php
(php stuff to call a specific table from DB)
?>
</body>
<html>
BTW the php variables I'm talking about are specific select statement from the DB.
ACTUAL CODE: or should select statements be at beg or sep file?
<table>
<tr>
<td align="left" width="200px">
Cover: Original Total
</td>
<td width="200px" align="center">
<?php
$original = "SELECT * FROM `comic_db`.`comic_db` WHERE comic_cover=\"original\"";
$orig_con = mysqli_query($comic_connect, $original);
$orig_total = mysqli_num_rows($orig_con);
echo $orig_total;
?>
</td>
</tr>
<tr>
<td width="200px" align="left">
Cover: Variants Total
</td>
<td width="200px" align="center">
<?php
$variants = "SELECT * FROM `comic_db`.`comic_db` WHERE comic_cover=\"variant\"";
$variant_con = mysqli_query($comic_connect, $variants);
$variant_total = mysqli_num_rows($variant_con);
echo $variant_total;
?>
</td>
</tr>
<tr>
<td align="left" width="200px">
Cover: Baby Totals
</td>
<td width="200px" align="center">
<?php
$baby = "SELECT * FROM `comic_db`.`comic_db` WHERE comic_cover=\"baby\"";
$baby_con = mysqli_query($comic_connect, $baby);
$baby_total = mysqli_num_rows($baby_con);
echo $baby_total;
?>
I'm assuming the repeated <html> tags in your example are just placeholders and would actually be <div>s and other elements making up the actual content of the page.
Your example is what's commonly called "spaghetti code" because it can quickly turn into an unmaintainable mess because you can't clearly see an overview of the HTML, nor can you see all the PHP code in one place.
The main thing to keep in mind is separating application logic (such as your database queries) from presentation (HTML and presentation logic like looping over an array to display it as an HTML list).
At the very least you'd want to put the main PHP code at the top of the file like you said, but it would be much better if it was in a separate file.
P.S. Any beginner book on PHP will discuss this in detail.
I've been working on some code and tested it on localhost, everything works fine, but when i upload it to my server it doesn't work beyond my php tags. No errors are showing either. I have checked both php versions and on localhost i run version 5.4.7 and on server it's version 5.3.21. Maybe this is causing the problem? Is there something I should look for in the phpinfo()? Am I missing something in my code?
Here is the code:
<!DOCTYPE html>
<?php phpinfo(); ?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<meta charset="utf-8">
<style>
body { background:black;}
.toggle { display:none; }
p {
width:570px;
text-align:justify;
color:#686868;
font-family:Georgia, serif;
}
h2 { color:black; }
button { background:#686868;
border:none;
font-family:Georgia, serif;
width:570px;
}
</style>
</head>
<body>
<?php
include('sql.php');
$i = 0;
while($i < count($rows)) {
echo "
<div>
<button class='trigger'>
<table width='100%'>
<tr>
<td width='20%'><img src='http://localhost/app-side/Icons/bar_icon.png' />
</td>
<td width='80%'><h2>{$rows[$i]['titel']} </h2></td>
</tr>
</table>
</button>
<div class='toggle'>
<p>
{$rows[$i]['info']}
</p>
</div>
</div>";
$i++;
}?>
</body>
<script>
$('.trigger').click(function() {
$(this).siblings('.toggle').slideToggle('fast');
});
</script>
</html>
When i run it, it shows a black background (as it's suppose to) but everything beyond my php starting tag gets cut off.
I have also tried to force my while loop to loop 10 times and also removed the parts where it's getting data from my database to see if it was a mysql related problem. Which I can conclude it's not.
The following line is the problem:
<img src='http://localhost/app-side/Icons/bar_icon.png
The image cannot being loaded as localhost refers to the local computer of the client (where the browser runs) not to your server. Usually such urls in websites are considered malicious ;)
A workaround to make it work on both localhost and server would be to use an relative path. This can be relative to your document or relative to the DOCUMENT_ROOT of your server. I've used the second approach as I don't know the location of your php file on server.
Solution with link relative to DOCUMENT_ROOT:
Replace:
<img src='http://localhost/app-side/Icons/bar_icon.png
by
<img src='/app-side/Icons/bar_icon.png
The only thing that I can assume is that $rows is empty and hence the following code does not get run:
// count($rows) could be equal to 0
while($i < count($rows)) { // this condition becomes false in that case
echo "
<div>
<button class='trigger'>
<table width='100%'>
<tr>
<td width='20%'><img src='http://localhost/app-side/Icons/bar_icon.png' />
</td>
<td width='80%'><h2>{$rows[$i]['titel']} </h2></td>
</tr>
</table>
</button>
<div class='toggle'>
<p>
{$rows[$i]['info']}
</p>
</div>
</div>";
$i++;
}
UPDATE
Based on your comment, it could then due to something inside sql.php, most probably database connection problem. Try putting error_reporting(E_ALL) at the very top of the page and see if that prints out any error.
Have you checked your sql.php to make sure you've changed it to match your live server (changed from localhost variables) also check your database field names versus your script for typos.
[code]
{$rows[$i]['titel']} </h2></td>
[\code]
Is it supposed to read :
[code]
{$rows[$i]['title']} </h2></td>
[\code]
If your database field name is "title" and
You are trying to get data from a field called
"titel" than that could cause your error.
I hope that helps
<?php
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=London');
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
?>
<html>
<head>
<title>Google Weather API</title>
</head>
<body>
<h1><?php print $information[0]->city['data']; ?></h1>
<h2>Today's weather</h2>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $current[0]->icon['data']?>" alt="weather"?>
<span class="condition">
<?php echo round(conver_f_c($current[0]->temp_f['data'])); ?>° C,
<?php echo $current[0]->condition['data'] ?>
</span>
</div>
<h2>Forecast</h2>
<?php foreach ($forecast_list as $forecast) : ?>
<div class="weather">
<img src="<?php echo 'http://www.google.com' . $forecast->icon['data']?>" alt="weather"?>
<div><?php echo $forecast->day_of_week['data']; ?></div>
<span class="condition">
<?php echo round(conver_f_c($forecast->low['data'])); ?>° C - <?php echo round(conver_f_c($forecast->high['data'])); ?>° C,
<?php echo $forecast->condition['data'] ?>
</span>
</div>
<?php endforeach ?>
</body>
</html>
<?php
function conver_f_c($F){
return $C = ($F − 32) * 5/9;
}
I want Out somthing like this manner of the horizontal ,
Even i tried UL LI WITH display inline but it goes failed,
Tell me some good suggestion for my probme,
I want exactly like horizontal, expecting exactly like screen shot ,
Tell me How to render using php
Thanks
alt text http://img163.imageshack.us/img163/7518/weatherhori.jpg
Above snippet present display out verticly , i want o change that verticle to horizonatal ,
somthing like this screen shot
<table>...</table>
Update
From your latest comment so far:
i know how to fetch array and display
it, but i dont know to fetch and
display in the verticl manner that is
the stuck up
I feel this is going to be a stupid answer but it appears to be what you don't understand...
The web is based in a markup language called HTML. This language has tags (delimited by angle-brackets) that allow you to define the structure of a document. On top of this, you have another language called CSS. This other lang allow you to define how HTML is going to be displayed on screen.
You may argue that you already have a web page and you've written it with the PHP language instead of the two other langs I've mentioned. That's not enterely true: you code in PHP, sure, but you use PHP to generate HTML. And it's HTML what finally reaches the browser (Firefox, Explorer...). PHP is executed in the web server, not in the browser. The browser can only see whatever HTML you've generated.
To sum up: you have to forget about PHP, Google and the whole weather thingy. You first need to write a static HTML document and style it with CSS. Once you've done with it, you can finally replace the parts of the information that are dynamic with values taken from your PHP variables.
And since you seem to need a table to display tabular data, the appropriate HTML tag is <table>:
<table>
<tr>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
<th>Sat</th>
</tr>
<tr>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
<td><img src="/path/to/pics/sunny.png" width="25" height="25" alt="Sunny"></td>
<td><img src="/path/to/pics/rainy.png" width="25" height="25" alt="Rainy"></td>
<td><img src="/path/to/pics/cloudy.png" width="25" height="25" alt="Cloudy"></td>
</tr>
<tr>
<td>26ºC</td>
<td>26ºC</td>
<td>22ºC</td>
<td>25ºC</td>
</tr>
<table>
I suggest you find some tutorials about basic HTML and CSS. They'll be of invaluable help.
This is what's done by Google :
http://jsfiddle.net/bW8NA/1