I am trying to pull some information from my database and put it in a modal. I went to the foundations website and tried to figure it out from their docs section. I dont exactly understand it. So I have a section of my site that allows users to request to delete a song they uploaded. Now if they click the X a modal should pop up and ask to confirm.
<div class="row">
<div class="large-8 column musicup">
<p> <?php echo "No music uploaded..."; ?> </p>
</div>
</div>
<?php
}else{
?>
<h2 style="margin-top:1em;">Music uploaded</h2>
<hr style="opacity:.4;">
<?php
while($row_a = mysql_fetch_array($res))
{
?>
<div class="row">
<div class="large-4 column musicup">
<p><?php echo $row_a['title']; ?></p>
</div>
<div class="large-3 column musicup"><span data-tooltip class="has-tip tip-top" title="<?php echo $row_a['reason']; ?>">
<div class="button <?php echo $row_a['status'];?>"><?php echo $row_a['status'];?></div>
</span></div>
<div class="large-3 column musicup_date">
<p><?php echo date('F j Y',strtotime($row_a['uploaded'])); ?> </p>
</div>
<div class="large-2 column musicup">
<p>X</p>
</div>
</div>
<?php
}
}
}
?>
</div>
So now I have the modal and all the database queries on a new page called song_delete.php.
Here is the code for that:
<?php
include_once "functions.php";
$query = sprintf("SELECT * FROM songs WHERE user_id = %d AND song_id = %d",$_SESSION['user_id'], $_GET['id']);
$res = mysql_query($query) or die('Error: '.mysql_error ());
$row_a = mysql_fetch_assoc($res);
$totalRows_a = mysql_num_rows($res);
?>
<div id="deleteMusic" class="reveal-modal medium">
<h2>Request to delete<span style="color:#F7D745;"> <?php echo $row_a['title']; ?></h2>
<p class="lead">Are you sure you want to delete this song? Please allow 2 full business weeks for deletion.</p>
<span style="float:right;">Cancel
Submit </span>
<a class="close-reveal-modal">×</a>
</div>
Thanks for any help in advance. I appreciate it.
Please dont tell me about the mysql_query and how I should use PDO or MySQLi and OOP i know this, but this site is not currently coded with all that..
OK first things first - its often better to look at the compile source (HTML Source Code) in these cases. Can you do this? From the code you've given it looks fine but without the css/js linking and showing the placement of the reveal code there's no way to tell.
How Foundation Reveals Work
1 - The modal code is placed just before the ending </body>.
2 - It should look something like this:
<div id="myModal" class="reveal-modal">
<h2>Awesome. I have it.</h2>
<p class="lead">Your couch. It is mine.</p>
<p>Im a cool paragraph that lives inside of an even cooler modal. Wins</p>
<a class="close-reveal-modal">×</a>
</div>
3 - Depending on the size you want you can use an extra class of .small (for a reveal size of 30% browser width. Or one of these (taken directly from Foundation Docs)
.medium: Set the width to 40%.
.large: Set the width to 60%.
.xlarge: Set the width to 70%.
.expand: Set the width to 95%.
4 - At this point you can attach data-reveal-id="<id of modal here>" or call the modal via foundation. At this point your modal will popup in all Foundation 4 supported browsers. However you need the javascript files to close it.
5 - Now make sure you have the necessary scripts
<!-- If running version with default scripts -->
<script src="foundation.js"></script>
<script src="foundation.reveal.js"></script>
6 - Then call $(document).foundation() and then via the magical jQuery javascript library it should work as intended :-).
Extras
You can add extras attributes to reveal if you wish this way (List of all the attributes
):
$(document).foundation('reveal',<options here>,<callback>)
Lastly you might want to take the ajax tag off this (you aren't calling any content in asynchronously - it's all compiled at runtime via your server
Related
Please am new in computer programming and am using php to develop a music website but i ran into a problem to keep occuring in different project that i have being building.
The problem is when ever am using a grid system either a css grid or a bootstrap grid system the grid keeps breaking due to padding to keeps adding automatically to any side of the grid as i uses the foreach loop to loop over many element on any side of the grid layout, this problem will always occur as far as one side of the grid has my content than the other side like maybe my side bar has many content that the main grid content vice versa ... please i don't know what to do, am using a css grid right now.. here are some screeen shot of how it will look..
enter image description here
Here is a sample of how i use my foreach loop to display many content from my database.
<?php $post = new media_data();
$posts = $post->get_posts(5);
$num_rows = $posts->num_rows;
echo '
<div class="show-slide-container">
<?php foreach ($posts as $no => $post) {
<div class="my-slides fade">
<div class="txt-number-sl">
<?php $no + 1 ?> / <?php $num_rows ?>
</div>
<a href="<?php 'single_posts.php?post-slug=' . $post['slug'] ?>">
<img class="img-sl" src="<?php 'static/images/' . $post['image']; ?>"
alt="<?php html_entity_decode(substrwords($post['title'], 230)); ?>">
</a>
<div class="txt-body-sl">
<?php html_entity_decode(substrwords($post['title'], 100)); ?>
</div>
</div>
'
} ?>
Actually I am beginner programmer in HTML, CSS and PHP. I have simple website for add and register in courses. The user should be add course into website and the courses should be posted on the site.so users can browse and register.
Actually my problem is how to call the course name from database and how to format it with HTML code as I want.
This is the page of courses which is content the list of available courses in website ( please note it is only HTML code, I do that to see how the page will be )
Screenshot of page:
So as you see, the first page include many this HTML code to add course list into website with the following code:
<div class="card card-1">
<a href="http://127.0.0.1/project2/course details/course1.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% "></a> <div class="container">
<h4 class="textstyle"><b>Operating System</b> </h4>
<p class="textstyle">Free Course</p>
</div>
</div>
what i want do with PHP?
I want to write a PHP code to replace the P and h4 with the course name, cost of courses from my database for each available course.
Please note: the pic for each course it will be from my pc, no need to call the pic from database.
I tried to write PHP code like below:
<div>
<div class="card card-1">
<a href="http://127.0.0.1/project2/course details/course1.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% "></a> <div class="container">
<?php
include_once("db.php");
$result = mysqli_query(OpenCon(), "SELECT Course_Name,cost FROM `course`");
//while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array
while($res = mysqli_fetch_array($result)) {
echo "<p>".$res['Course_Name']."</p>";
echo "<p>".$res['cost']."</p>";
}
?>
</div>
</div>
</div>
This is my result:
It's okay but I want the style to be like the first screenshot. each course should have picture.
After that when the user click on course name. I want move to another page which is content the course details ( for the same course that user clicked ) also it's called for my database
like this:
I hope any one help my to solve this problem only, I should solve this problem within 2 days only. and sorry if my explanation is bad.
Thanks in advance for everyone.
Put the code in a PHP loop.....
So, this
<div class="card card-1">
<a href="http://127.0.0.1/project2/course details/course1.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% ">
</a>
<div class="container">
<h4 class="textstyle"><b>Operating System</b> </h4>
<p class="textstyle">Free Course</p>
</div>
</div>
Becomes (after cleaning up the code a bit - I think you didn't mean to use two <p> in there, but I left them so you can see it. Note that using different lines for the segments makes it a lot easier to see what you have.)
include_once("db.php");
$result = mysqli_query(OpenCon(), "SELECT Course_Name,cost FROM `course`");
$count = 0;
while($res = mysqli_fetch_array($result)) {
$count ++;
// NOTE: Here is the LOOP! - not outside the query, but INSIDE it
// First you 'jump out' of PHP, going back to HTML
?> <!-- now you are in HTML (when you need PHP again, you 'jump in' and 'jump out' as needed - see the code below....) -->
<div class="card card-<?php echo $count;?>">
<a href="http://127.0.0.1/project2/course details/course<?php echo $count;?>.php">
<img src="http://127.0.0.1/project2/icons/coursepic.jpg" alt="Avatar" style="width:101% ">
</a>
<div class="container">
<h4 class="textstyle">
<b><p><?php echo $res['Course_Name'];?></p></b>
</h4>
<p class="textstyle">
<p><?php echo $res['cost'];?></p>
</p>
</div>
</div>
<?php // we are in PHP again....
}
That should do what you asked for - though I would go a step (well, more than one...) further and make as much of this dynamic as you can.
For this I will presume that:
your database table has a column called 'id' (if it doesn't, you should have) and it relates to the course number (you could make a course number column if they don't match up, but I'm keeping it simple)
you have all your pictures labeled 'coursepicX' where the X is the course number.
We'll use 'coursepic' as a default in case there isn't a picture yet...
Now, the code is more dynamic!
include_once("db.php");
$result = mysqli_query(OpenCon(), "SELECT id,Course_Name,cost FROM `course`");
while($res = mysqli_fetch_array($result)) {
// NOTE: Here is the LOOP! - not outside the query, but INSIDE it
// First you 'jump out' of PHP, going back to HTML
?> <!-- now you are in HTML (when you need PHP again, you 'jump in' and 'jump out' as needed - see the code below....) -->
<div class="card card-<?php echo $res['id']?>">
<a href="http://127.0.0.1/project2/course details/course<?php echo $res['id']?>.php">
<?php
$pic = "http://127.0.0.1/project2/icons/coursepic.jpg";
if(file_exists("http://127.0.0.1/project2/icons/course" . $res['id'] . ".jpg") {
$pic = "http://127.0.0.1/project2/icons/course" . $res['id'] . ".jpg";
}
<img src="<?php echo $pic; ?>" alt="Avatar" style="width:101% ">
</a>
<div class="container">
<h4 class="textstyle">
<b><p><?php echo $res['Course_Name'];?></p></b>
</h4>
<p class="textstyle">
<p><?php echo $res['cost'];?></p>
</p>
</div>
</div>
<?php // we are in PHP again....
}
Note that this is the basic 'shopping cart' sort of program - you will likely use it many (many) times in your career.
Happy Coding!
I'm building a wordpress site (here: http://dev.tps.entropii.com/contact-us/) that requires a full page width google map on the contact page. The Business has two addresses so they effectively need two maps with a means to switch between them. I'm using Advanced Custom Fields plugin to give the user the functionality to update/edit their addresses.
Here's the problem. In order to give the functionality to switch back and forth between the two maps I decided to put them inside a twitter bootstrap carousel. One slide for each map. This works as expected with one problem. The map that is contained within the inactive slide (e.g. the slide that doesn't have the class 'active' on page load), doesn't seem to fully load. If I put the maps side by side on the page without the carousel they load no problem.
Because I'm using advanced custom fields, the maps are being loaded using php. Here's the HTML/php from my template file:
`
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<!-- map 1 -->
<?php $map1 = get_field('map_1'); if( !empty($map1) ): ?>
<div class="acf-map" id="map1">
<div class="marker" data-lat="<?php echo $map1['lat']; ?>" data-lng="<?php echo $map1['lng']; ?>"></div>
</div>
<?php endif; ?>
</div>
<div class="item">
<!-- map 2 -->
<?php $map2 = get_field('map_2'); if( !empty($map2) ): ?>
<div class="acf-map" id="map2">
<div class="marker" data-lat="<?php echo $map2['lat']; ?>" data-lng="<?php echo $map2['lng']; ?>"></div>
</div>
<?php endif; ?>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#map-carousel" data-slide="prev"></a>
<a class="right carousel-control" href="#map-carousel" data-slide="next"></a>
</div>`
My suspicion is that because the inactive slides of the bootstrap carousel are set to display none, that the content isn't being loaded int he first place properly. However I'm completely stabbing in the dark. Can anyone shed any light on this?
Let me know if you ned any more info. Thanks,
apologies if this has been covered anywhere here. I tried searching, but only found topics related to styling and positioning captions within the carousel code…
So, I have a layout that contains three columns:
The left column contains general information related to each page/project.
The center column contains a Bootstrap 3 carousel with images.
The right column is where I was planning on displaying all the captions related to the images in the center Carousel.
I can't quite figure out how to get the captions working in the right column. To clarify, the captions will change with each carousel slide, just as they do in the default carousel setting. I basically want to move the captions off the image, and into the right column.
I am using Kirby (www.getkirby.com) as my CMS and I am using a foreach loop to get the code for the images, etc. in the carousel. Here is my current code, including the caption section (which I am trying to move…)
<div id="center" class="col-xs-12 col-sm-6 col-md-8">
<?php $imagepage = $page->children()->first() ?>
<?php if($imagepage->hasImages()): ?>
<div id="merry-go-round" class="carousel slide">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<?php $n=0; foreach($imagepage->images() as $image): $n++; ?>
<div class="item<?php if($n==1) echo ' active' ?>">
<img style="display:block; margin-left: auto; margin-right: auto;" src="<?php echo $image->url() ?>" alt="<?php echo html($image->title()) ?>" class="img-responsive">
<div class="carousel-caption"><?php echo $image->img_title() ?></div>
</div>
<?php endforeach ?>
<?php endif ?>
</div><!-- /carousel-inner -->
<!-- Controls -->
<a class="left carousel-control" href="#merry-go-round" data-slide="prev"></a>
<a class="right carousel-control" href="#merry-go-round" data-slide="next"></a>
</div><!-- /merry-go-round -->
</div><!-- /#center -->
<div id="right" class="col-xs-12 col-sm-3 col-md-2">
<p>THIS IS WHERE I AM TRYING TO PUT THE CAROUSEL CAPTIONS…</p>
</div><!-- /#right -->
I've tried by best but I am all out of ideas. I thought maybe I could do something like make the caption a variable:
<?php $test_caption = $image->img_title() ?><?php echo $test_caption ?>
but this doesn't work outside the carousel area. I'm guessing it's that it won't work outside of the foreach loop?
Anyway, if anyone has any suggestions I would really appreciate it. I'm learning PHP as I go along, but I don't know any javascript so I'm hoping there's a solution outside that. And again, I'm using Bootstrap 3.
Here is a link to a fiddle I made (without all the php stuff…):
http://jsfiddle.net/4tMfJ/2/
Based on Twitter Bootstrap Carousel - access current index
You can add the code below to your javascript (after loading jquery / bootstrap)
$(function() {
$('.carousel').carousel();
var caption = $('div.item:nth-child(1) .carousel-caption');
$('#right h1').html(caption.html());
caption.css('display','none');
$(".carousel").on('slide.bs.carousel', function(evt) {
var caption = $('div.item:nth-child(' + ($(evt.relatedTarget).index()+1) + ') .carousel-caption');
$('#right h1').html(caption.html());
caption.css('display','none');
});
});
also see: http://jsfiddle.net/4tMfJ/3/
Thanks Bass for your answer it worked for me !
But i did not want to have replicated content so i did it my way ;)
$("#slider").on('slide.bs.carousel', function(evt) {
var step = $(evt.relatedTarget).index();
$('#slider_captions .carousel-caption:not(#caption-'+step+')').fadeOut('fast', function() {
$('#caption-'+step).fadeIn();
});
});
http://jsfiddle.net/4fBVV/3/
I'm finding that placing php code snippets within my website's & tags is causing a problem with the code after it's placement. I first noticed it when placing avatars on my site in a list format where it works fine up to a point and then the same image is repeated for the rest of the list. Here is the code that I'm uisng for that:
<?php
$show_user .= "
<div class=\"section\">
<div class=\"sectionInner\">
<div class=\"searchAvatar\"><img class=\"searchAvatarSize\" src=\"uploads/avatars/$member_avatar\"></div>
<div class=\"searchInformation\"><div class=\"searchInformationPrimary\">$member_name</div><div class=\"searchInformationSecondary\"><i>"$member_summary"</i></div></div>
<div class=\"searchInformation\"><div class=\"searchInformationPrimary\">$member_subtype $member_type</div><div class=\"searchInformationSecondary\">$member_city, $member_county</div><div class=\"searchInformationThird\">View Details</div></div>
<div class=\"clearLeft\"></div>
</div>
</div>
<div class=\"searchResultSplitter\"></div>
";
?>
<?php echo $show_user; ?>
I'm now noticing it when placing php within my navigation bar where it's not closing the tag. Here is my code for the bar:
<div id="pageSubNavigation" class="page<?php echo $thispage; ?>SubNavigation">
Next Page
</div>
After this, all of the other tags show the same link. Any ideas why this might be?
You need to either jump out of the HTML to add the variables or wrap them in {} so they appear correctly.
Example:
<div class=\"searchAvatar\"><img class=\"searchAvatarSize\" src=\"uploads/avatars/".$member_avatar."\"></div>
or
<div class=\"searchAvatar\"><img class=\"searchAvatarSize\" src=\"uploads/avatars/{$member_avatar}\"></div>
Check out this article about string formatting with variables in PHP.