PHP/Html file into a html 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
I am a newbie in coding etc. so I am trying to get some help from you guys. I have to put every single file (.php) in one .html/php file.
Now I got this code:
<html>
<head>
<style type='text/css'>
span {
text-decoration:underline;
color:blue;
cursor:pointer;
}
</style>
<script>
// show the given page, hide the rest
function show(elementID) {
// try to find the requested page and alert if it's not found
var ele = document.getElementById(elementID);
if (!ele) {
alert("no such element");
return;
}
// get all pages, loop through them and hide them
var pages = document.getElementsByClassName('page');
for(var i = 0; i < pages.length; i++) {
pages[i].style.display = 'none';
}
// then show the requested page
ele.style.display = 'block';
}
</script>
</head>
<body>
<p>
Show page
<span onClick="show('Page1');">1</span>,
<span onClick="show('Page2');">2</span>,
<span onClick="show('Page3');">3</span>.
</p>
<div id="Page1" class="page" style="">
Content of page 1
</div>
<div id="Page2" class="page" style="display:none">
Content of page 2
</div>
<div id="Page3" class="page" style="display:none">
Content of page 3
</div>
</body>
So my question is; how do i put my files into the 'Content of page 1/2/3'?
Thanks in advance!

Try include("[path to your file]"); or include_once("[path to your file]");
http://php.net/manual/en/function.include.php
http://php.net/manual/en/function.include-once.php

If you need to combine other PHP files with this HTML file, simply change the name of this file to .php if it isn't already. Then copy/paste your code (in order each file is processed) into the top of this file. Be sure to surround your php with <?php and ?>. The HTML will still display correctly if it's inside a PHP file.
Note: This is not good practice, but it will accomplish what your teacher is requesting.

Related

How to hide/show more text within a forEach loop [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
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.
Closed 5 years ago.
Improve this question
My code is :
<?php
$msgArray = [
0=>'HTTP means HyperText Transfer Protocol.',
1=>'HTTPS,Hyper Text Transfer Protocol Secure is the secure version of HTTP.'
];
foreach ($msgArray as $key => $msg) :
$small = substr($msg, 0, 5);?>
<span class="lessText"><?= $small ?></span>
<span class="fullText" style="display: none"><?= $msg ?></span>
<sub class="viewMore" style="color:#3399ff;padding-left2%;cursor: pointer;">view more >></sub>
<sub class="viewLess" style="color:#3399ff;padding-left2%;cursor: pointer;display: none"><< view less</sub>
<?php endforeach; ?>
<script type="text/javascript">
$(".viewMore").click(function(){
$(".viewMore").hide();
$(".lessText").hide();
$(".fullText").show();
$(".viewLess").show();
});
$(".viewLess").click(function(){
$(".viewLess").hide();
$(".fullText").hide();
$(".lessText").show();
$(".viewMore").show();
});
</script>
Here, I am trying to display a long string to its 1st five character and after clicking view more it will be displayed the whole string.
this is working fine if there is only one. Inside the forEach loop its not working properly. Please solve this problem.
Wrap the HTML fragment in a container.
<div class="container">
<span class="lessText"><?= $small ?></span>
<span class="fullText" style="display: none"><?= $msg ?></span>
<sub class="viewMore" style="color:#3399ff;padding-left2%;cursor: pointer;">view more >></sub>
<sub class="viewLess" style="color:#3399ff;padding-left2%;cursor: pointer;display: none"><< view less</sub>
</div>
Then modify your script to use DOM traversal method to target the desired element. Using .closest() traverse up to common parent i.e. container then using it as context or use .find()
$(".viewMore").click(function () {
var container = $(this).closest('.container')
$(".viewMore, .lessText", container).hide(); //container.find('.viewMore, .lessText').hide()
$(".fullText, .viewLess", container).show();
});
$(".viewLess").click(function () {
var container = $(this).closest('.container')
$(".viewLess, .fullText", container).hide();
$(".lessText, .viewMore", container).show();
});
Write it in this structure:
<?php foreach(): ?>
<div class="holder">
<div class="lessText"></div>
<div class="fullText"></div>
<div class="viewMore"></div>
<div class="viewLess"></div>
</div>
<?php endforeach; ?>
JS:
$('.holder .viewMore').click(function(){
$(this).closest('.holder').find('.lessText').hide();
$(this).closest('.holder').find('.fullText').Show();
});
$('.holder .viewLess').click(function(){
$(this).closest('.holder').find('.lessText').Show();
$(this).closest('.holder').find('.fullText').hide();
});

Show / Hide Div containing php Jquery

Iam trying to have 3 buttons, and when i press one, it will show the content of a php file. This is what i have done so far:
In the main Html file:
<div class="buttons">
<a class="showSingle" target="1">Logg</a>
<a class="showSingle" target="2">Saker</a>
<a class="showSingle" target="3">Rediger Kunde</a>
</div>
<div id="div1" class="targetDiv"><?php include 'php/loggselect.php'; ?></div>
<div id="div2" class="targetDiv">Saker</div>
<div id="div3" class="targetDiv">Rediger </div>
And later in the same file:
<script type="text/javascript">
jQuery(function(){
jQuery('.showSingle').click(function(){
jQuery('.targetDiv').hide();
jQuery('#div'+$(this).attr('target')).show();
});
});
</script>
Have two problems: When I reload the page, all 3 divs are showing, I have to press one of the "buttons" to only show the content of that spesific button.
The next and biggest problem is that this is working fine as long as it is plain text. But when I use <?php include 'php/loggselect.php'; ?> it will no longer show / hide. The php file should display a table with search result from my database. But it does not work when the php only contains `
echo 'testing';
?>` either. Any soulution?
Thanks!
Problem #1: You can do,
CSS: .hiddenDiv {display:none;}
And add this class to every div
$(function(){
$(".showSingle").eq(0).trigger("click");
});
Problem #2: Do
var _var1 = "variableone";
$("#div1").load('php/loggselect.php?v1='+_var1+'&v2='+_var1);
Don't do <?php ... ?>

pull Else if from SQL [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 need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}

Selecting php out with JQuery [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
This is a code snippet I have and I would like to be able to select the out of PHP. When I try to grab the PHP output and store it into a variable, I receive "undefined".
<h1 id=<?php echo '$test; ?> class="list-name--original">
My last attempt I tried this code:$("h1.list-name--original")[0].outerHTML);
Why not just put all your PHP output in a variable
<script>
var data = '<?=$test?>';
</script>
You can then set the contents of an H1 tag like this
<h1 id="myid"></h1>
<script>
$('h1#myid').text(data);
</script>
Try
<h1 id="<?php echo $test; ?>" class="list-name--original">
in jQuery
$(".list-name--original").html();
or
$("#<?= $test ?>").html();
Try this:
<?php $test = "Hello world!"; ?>
<h1 id="example" class="list-name--original"><?php echo $test; ?></h1>
<script language="javascript">
$("#example").html();
</script>

HTML div mapping [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
If I defined some div in a code like this:
if(...)
{
// code
// code again
if(...)
{
// code
<div> first div </div>
//code code
}
}
<div> second div </div>
So "first div" always appears before the "second div", how can I switch the order of div's displaying? Thanks.
how about this (you need div id's)
$('#secondDiv').insertBefore('#firstDiv').remove();
Change your code to:
if(...)
{
// code
// code again
if(...)
{
// code
<div id='firstDiv'> first div </div>
//code code
}
}
<div id='secondDiv'> second div </div>
You can show the second <div> in a predetermined place by appending it to another div. For example:
HTML:
<div id="fake-second"></div>
<div id="first"> first div </div>
<div id="second"> second div </div>
jQuery:
$("#fake-second").append($("#second").html());
$("#second").hide();
JS Fiddle Demo

Categories