The GOAL:
Click of a “next slide” button refreshes / replaces <div> content with new content from a different php file. Each slide is its own php file. This is for an online course I’m building. Each time the button is clicked the <div> existing content is replaced by new content from the next slide (php file) in the series. I also want to build a back button to go to the previous slide, but I’m not at this point yet.
The PROBLEM:
I’m currently trying to use jquery/ajax. The button works (refreshes the <div> with the new slide content) in the first two slides, but then does not work on the third slide. I placed the button on each slide (prefer it this way). This may be one of the problems. I thought another issue may have to do with the file path for the page variable. I'm also wondering if the problem has to do with the fact that the home page only “includes” the other files in Div’s. Like this:
<div id="header">
<?php include 'pf_header.php'; ?>
</div>
<div id="menu">
<?php include 'pf_menu.php'; ?>
</div>
<div id="content">
<?php include 'pf_welcome.php'; ?>
</div>
<div id="footer">
<?php include 'pf_footer.php'; ?>
</div>
All of my code is below:
Script.js
$(document).ready(function() {
$(".slide").on("click", function(e){
$(".content").load($(this).attr("page"));
});
});
Slide 1 (button works)
<div class="content">
<div id="main">
<input type="button" value="NEXT" id="nextbtn" class="slide" page="pf_instructions.php">
</div>
<div id="sidebar">
<div id="aside1">
<iframe src="https://www.youtube.com/embed/NAeha727ZWI"></iframe>
</div>
<div id="aside2">
</div>
</div>
</div>
Slide 2 (button works)
<div class="content">
<div id="main">
<p>INSTRUCTIONS</p>
<p>INSTRUCTIONS</p>
<input type="button" value="NEXT" id="nextbtn" class="slide" page="basics/pf_l1_introduction.php">
</div>
<div id="sidebar">
<div id="aside1">
<iframe src="https://www.youtube.com/embed/NAeha727ZWI"></iframe>
</div>
<div id="aside2">
</div>
</div>
</div>
Slide 3 (button DOES NOT work)
<div class="content">
<div id="main">
<p></p>
<input type="button" value="NEXT" id="nextbtn" class="slide" page="basics/pf_l1_quiz.php">
</div>
<div id="sidebar">
<div id="aside1">
<iframe src="https://www.youtube.com/embed/NAeha727ZWI"></iframe>
</div>
<div id="aside2">
</div>
</div>
</div>
Related
I've created a file called menu.php to be my universal nav/menu file. The way it was created using bootstrap though, I have a div called article at the bottom which serves as the main body of the app, since the sidebar in my menu is expandable/responsive.
I really want to have one global menu file. I'm currently including it in all of my content pages like so:
<?php include("menu.php")?>
This works but it breaks my formatting. What I'm trying to do is make all of my main pages such as index.php have the html formatted so that it will always sit inside the tag in my code below which shows card classes.
<header>
<div class="branding">
<div class="menu-button menu-toggle nav">
<i class="material-icons">menu</i>
</div>
<img src="" />
</div>
<div class="page-details">
</div>
<div class="settings">
<div class="menu-button profile">
<i class="far fa-user-circle fa-2x"></i>
</div>
<div class="menu-button menu-toggle aside">
<i class="material-icons">chat</i>
</div>
</div>
</header>
<div class="app">
<nav>
<div class="title-block">
<img src="" />
</div>
<ul>
<li><a href="#"><i class="material-icons">home</i>
<span>Home</span></a></li>
</ul>
</nav>
<!--This following article section is the main body of the page, that I want each additional page to take up-->
<article>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</article>
</div>
Example:
Menu.php is my global menu/nav file but it makes the page/app act as a wrapper for all the other pages (index.php, editor.php, etc.)
menu.php
<div class="app">
<nav>
Nav menu content
</nav>
<article>
This will be the main page article for index.php, editor.php,etc.
</article>
</div>
example with index.php (the start and end are just hypothetical to show the endpoints)
<body>
<?php include("menu.php");?>
<?php start('article') ?>
<!--Everything from here to the end() call would be inserted in the article tags on menu.php-->
<div class="app">
<div id="content">
<div>
<h1 style="text-align: center; color: #A9BD50; ">Content Management Editor</h1>
</div>
<form method="post">
<textarea id="mytextarea"></textarea>
</form>
<div>
<h1 style="text-align: center; color: #A9BD50; ">Preview</h1>
</div>
</div>
</div>
<?php end() ?>
</body>
I am creating a project on PHP. But I have a problem. I want to pass some values from a section to another section. For example: In first section I am showing all products, and second section I am showing product details. When I click a product on first section, products values should pass second section. I am sharing my codes. Thanks
First Section
<section class="section pb-60 sm-pt-90">
<!-- Portfolio Items -->
<div id="portfolio-gallery" class="portfolio-container isotope-container portfolio-gallery row animated mfp-gallery" data-animation="fadeInUp" data-animation-delay="1200">
<article class="portfolio-item isotope-item col-md-4 col-sm-6 tasarim">
<div class="project-container">
<a href="http://blogaktuel.com//upload/Ekran Alıntısı.PNG" data-size="1080x1440" class="portfolio-gallery__img--main">
<img src="http://blogaktuel.com//upload/Ekran Alıntısı.PNG" alt="" style="width:360px; height:256px;">
<div class="overlay">
<div class="overlay-wrapper">
<div class="overlay-inner background-dark-5 opacity-70"></div>
</div>
</div>
</a>
<div class="project-details">
<h4 class="project-title heading-uppercase">Yeni Proje Mesela</h4>
</div>
</div>
</article>
Second Section
<div id="detay" class="ed-slide">
<div class="slide-container">
<div class="slide-content">
<section class="section sm-pt-0">
<div class="container">
<h2 class="text-white text-center animated" data-animation="fadeInDown"><!-- Project Title --></h2>
<div class="divider divider-alt divider-center divider-light animated" data-animation="fadeInDown" data-animation-delay="300"><span></span></div>
<p class="lead text-white mb-50 text-center animated" data-animation="fadeInDown" data-animation-delay="600"><!-- Project Info --></p>
<!-- Project Images etc. -->
</div>
</section>
</div>
</div>
</div>
You can make that using 2 ways:
-First way: when clicking on a product, you reload the page, and you pass the id in the url, and you display the data in the other section.
-Second way(Best way): via jquery for example, when clicking on a product, you load the data for this product and you display it in the other section.
I solved my problem with jQuery. I am sharing jQuery codes.
$(".details").click(function(){
var proje_baslik = $("input[name=proje_baslik]").val();
var proje_aciklama = $("input[name=proje_aciklama]").val();
var proje_url = $("input[name=proje_url]").val();
var proje_fiyat = $("input[name=proje_fiyat]").val();
var proje_resim = $("input[name=proje_resim]").val();
$("#detay .proje_baslik").html(proje_baslik);
$("#detay .proje_aciklama").html(proje_aciklama);
window.location.href = "http://localhost:81/Projeler/kodaktuelOnePage/#detay";});
Thanks for all comments
So what i'am trying to do is that I have a PHP page that gets the ID for some text stored in a database (Varchar) and I wish to display this content in my HTML page. So I can update the content in the database and the edit take effect across the site.
PHP:
$id = $_GET['id'];
// do some validation here to ensure id is safe
$link = mysql_connect("localhost", "root", "");
mysql_select_db("images");
$sql = "SELECT review FROM reviews WHERE id=$id";
$result = mysql_query("$sql");
$row = mysql_fetch_assoc($result);
mysql_close($link);
echo $row['review'];
I wish to display the content where is says "PHP content here"
HTML:
<div class="modal fade" id="albumModal1">
<div class="modal-dialog">
<div class="modal-content">
<!-- Top right close X -->
<div class="close-modal" data-dismiss="modal">
<span class="glyphicon glyphicon-remove"</span>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="modal-body">
<p class="modalTitle">The Beatles: Abby Road</p>
<img src="beatles.jpg" class="img-responsive center-block albumImgGrey">
<!-- Album 1's Review -->
<div class="modalText">
<p>Content upon content upon more content
<p>upon more content</p>
Content upon content upon more content
<p>upon more content</p>
<div class="starcolor">
<span>★ ★ ★ ★ ★</span>
</div>
</p>
<!-- PHP content here....... -->
<!-- PHP content here....... -->
<!-- Bottom of the review links -->
<ul class="list-inline item-details">
<li>
Year of release: <strong>3000</strong>
</li>
<li>
Previous Album: <strong>Hippie tree</strong>
</li>
<li>
Following Album: <strong>Backup Plus++</strong>
</li>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Any help or advice would be greatly appreciated.
Add this code:
<?php echo $row['review'];?>
where you have PHP content here, ensure you include the PHP tags.
STOP USING THE MYSQL EXTENSION, A KITTEN AND TWO PUPPIES DIE ANYTIME YOU DO THIS
Learn pdo or mysqli instead.
You can put your database result in a php file and then Web server will parse that php code and generate the required output.
It should be like.
output.php
<?php
<div class="modal fade" id="albumModal1">
<div class="modal-dialog">
<div class="modal-content">
<!-- Top right close X -->
<div class="close-modal" data-dismiss="modal">
<span class="glyphicon glyphicon-remove"</span>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<div class="modal-body">
<p class="modalTitle">The Beatles: Abby Road</p>
<img src="beatles.jpg" class="img-responsive center-block albumImgGrey">
<!-- Album 1's Review -->
<div class="modalText">
<p>Content upon content upon more content
<p>upon more content</p>
Content upon content upon more content
<p>upon more content</p>
<div class="starcolor">
<span>★ ★ ★ ★ ★</span>
</div>
</p>
<!-- PHP content here....... -->
$id = $_GET['id'];
$link = mysql_connect("localhost", "root", "");
mysql_select_db("images");
$sql = "SELECT review FROM reviews WHERE id=$id";
$result = mysql_query("$sql");
$row = mysql_fetch_assoc($result);
mysql_close($link);
echo $row['review'];
<!-- PHP content here....... -->
<!-- Bottom of the review links -->
<ul class="list-inline item-details">
<li>
Year of release: <strong>3000</strong>
</li>
<li>
Previous Album: <strong>Hippie tree</strong>
</li>
<li>
Following Album: <strong>Backup Plus++</strong>
</li>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
?>
<div class="modal-dialog"> <div class="modal-content"> <!-- Top right close X --> <div class="close-modal" data-dismiss="modal"> <span class="glyphicon glyphicon-remove"</span> </div> <div class="container"> <div class="row"> <div class="col-lg-8 col-lg-offset-2"> <div class="modal-body"> <p class="modalTitle">The Beatles: Abby Road</p> <img src="beatles.jpg" class="img-responsive center-block albumImgGrey"> <!-- Album 1's Review --> <div class="modalText"> <p>Content upon content upon more content <p>upon more content</p> Content upon content upon more content <p>upon more content</p> <div class="starcolor"> <span>★ ★ ★ ★ ★</span> </div> </p> <!-- PHP content here....... --> <!-- PHP content
<?php echo $row['content']; ?>
here....... --> <!-- Bottom of the review links --> <ul class="list-inline item-details"> <li> Year of release: <strong>3000</strong> </li> <li> Previous Album: <strong>Hippie tree</strong> </li> <li> Following Album: <strong>Backup Plus++</strong> </li> </ul> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> </div> </div> </div>
I have a piece of jquery code which load a file as
$(".data_container").load(base_path+"sign_up/signup.php?trigger_id=random");
Signup.php contains
<?php include_once("../libs/php_header/php_header.php"); ?>
<div class="ui modal s_umodal">
<i class="close icon"></i>
<div class="header">
Modal Title
</div>
<div class="image content">
<div class="image">
An image can appear on left or an icon
</div>
<div class="description">
A description can appear on the right
</div>
</div>
<div class="actions">
<div class="ui button">Cancel</div>
<div class="ui button">OK</div>
</div>
</div>
<script>
$('.s_umodal')
.modal('show');
</script>
The problem is, I can call the modal box and it shows up. but next time I click on the trigger button (button to show modal) it display another one even though I have closed the previous one. so now I am left with two modal boxes. and if I click multiple times i will be left with multiple modal boxes. I am using Semantic-UI.
The problem with your implementation is that every time you call $('.data_container').load(base_path+"sign_up/signup.php?trigger_id=random"); you are creating a new dom element with the div you are fetching from that ajax call. $('.s_umodal').modal('show'); is then showing all of the modal boxes returned from the server.
Without restructuring your code significantly, One approach is to not keep fetching the content of the div over and over again. The <div> will be a part of the main html that contains data_container. Your Ajax call can return the script that shows the dialog box.
HTML:
<div class="data_container"></div>
<div class="ui modal s_umodal">
<i class="close icon"></i>
<div class="header">
Modal Title
</div>
<div class="image content">
<div class="image">
An image can appear on left or an icon
</div>
<div class="description">
A description can appear on the right
</div>
</div>
<div class="actions">
<div class="ui button">Cancel</div>
<div class="ui button">OK</div>
</div>
</div>
Your Ajax call could be returning:
<script>
$('.s_umodal').modal('show');
</script>
Your call to load the content could remain the same.
$(".data_container").load(base_path+"sign_up/signup.php?trigger_id=random");
If you are up for a significant change however, You can try to use JSON web services instead of returning <script>.
I am trying to include different php files in the index.php file
on my webpage
http://www.e-lang.de/index.php
but the contents are included as simple text. What I want is that they should be proper DOM elements not the text.
here is my index.php
<div class="container">
<div class="navbar mt10">
<div class="navbar-inner">
اردو ایڈیٹر
<ul class="nav">
<li class="active">صفحۂ اول</li>
<li>رابطہ</li>
</ul>
</div>
</div>
<?php include_once "editor.php"; ?>
<!-- hidden inline form -->
<?php include_once "emailform.html"; ?>
</div>
and editor.php looks like
<div class="well widget">
<div class="widget-header">
<h3 class="title">اُردوھے جس کا نام</h3>
</div>
<div class="row">
<div class="span7">
<form method="post" action="save.php" id="text-container">
<input type="hidden" name="save" value="0" id="savetext">
<textarea rows="22" id="text-urdu" name="text" class="span7" dir="rtl" style="font: normal 25px Arial"></textarea>
</form>
<div class="rel">
<div id="counter"></div>
</div>
</div>
<div class="span4" id="help-wrapper">
</div>
</div>
<div class="row">
<div class="span11">
<div class="well widget" id="buttons-listing">
<ul class="listing">
<li>Print</li>
<li>Save</li>
<li>pdf</li>
<li></li>
<li><a href="#" class="button" id="btn_email" >E-Mail</a></li>
</ul>
</div>
</div>
</div>
</div>
There is no actual PHP in editor.php. Please remove the first line (containing the PHP open tag, <?php) from the editor.php file, as that should only surround PHP code. For standard HTML, you don't need to use the <?php tag.