JQuery mobile add collapsible content dynamically php - php

I am building a webapp with jquery mobile where I need to get data from external database and show that data as collapsible content.
<div data-role="collapsible" data-theme="b" data-content-theme="d" data-collapsed="true">
<?php
// display the results returned
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
printf('<h3><b> %s </h3>
<p> %s <p>',$row["OSO"], $row["AIKA"]);
}
?>
How can I make every H3 to appear as a collapsible content title? Now only the first is shown as a title and the rest are in the content section

You should make a new collapsible item for each entry if you want multiple headers...
<?php
// display the results returned
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<div data-role="collapsible" data-theme="b" data-content-theme="d" data-collapsed="true">
<h3><?= $row["OSO"] ?></h3>
<p><?= $row["AIKA"] ?><p>
</div>
<?php } ?>

Related

Get id of the vehilce for which button was pressed

I want to make some kind of booking system. I am displaying all data about cars from the database with buttons(which is a link that directs to the booking page) in "boxes", each box is for one car. I want to get id of the car for which the user pressed the button in box where the car is.
Here is my code
<!-- Fetching data from rows -->
<?php
while($rows = $result->fetch_assoc())
{
?>
<div class="car_box">
<div class="car_title">
<p><b><?php echo $rows['Brand'],' ', $rows['Model'];?></b></p>
</div>
<div class="car_description">
<div class="car_details">
<!-- ENGINE CAPACITY -->
<p>
<b>Engine capacity: </b> <?php echo $rows['Engine_capacity']; ?> cm3
</p>
(...)
<!-- BOOKING -->
<div class="booking">
Book now
</div>
</div>
You could try adding a parameter to your link.
Book now
and retrieve it in your Bookings.php by using $_GET['id'].

ACF get next sub_field data to current row

I'm using slick slider with ACF fields (Wordpress). I am trying to get the next and previous post title to the current slide (.slick-current).
I have three active slides with the class .slick-active, the middle one having also the class .slick-current(in addition to .slick-active)
<?php if (have_rows('videofeed','option')): ?>
<div class="slider-popular">
<?php while (have_rows('videofeed2','option')) : the_row(); ?>
<div class="slider-go-wrap">
<h2 class="video-title"> <?php the_sub_field('video_title'); ?> </h2><!-- the video title -->
<div class="video-controls">
<div class="prev-title-popular">
<span class="lightspan controltitles prev-videotitle">PREVIOUS TITLE HERE</span> <!-- previous ACF row sub_field "video_title" here -->
</div>
<div class="next-title-popular">
<span class="lightspan controltitles next-videotitle">NEXT TITLE HERE</span><!-- next ACF row sub_field "video_title" here -->
</div>
</div>
</div>
<?php endwhile;?>
</div>
<?php endif; ?>
Not being a very server side person, how would I integrate the following php loop into my ACF field repeater with the next and previous field data in the current slide? Is there an simpler way to do this than the php loop?
$rows = get_field('videofeed');
if($rows)
{
foreach($rows as $index => $row)
{
// from there, you can get prev / next data using loop index ($rows[$index-1] / $rows[$index+1]
}
}
Any advice from here would be great.
Issue solved with the following jQuery code, works for each slide:
$('.slider-go-wrap').each(function() {
currentSlide = $(this);
nextSlide = currentSlide.next();
prevSlide = currentSlide.prev();
nextSlideData = nextSlide.find('.video-title').html();
prevSlideData = prevSlide.find('.video-title').html();
currentSlide.find('.next-videotitle').html(nextSlideData);
currentSlide.find('.prev-videotitle').html(prevSlideData);
});

PHP putting the right row in the right html div

This one is going to be a bit hard to explain but I am going to try my best.
I have a database with a table called content with 3 columns, I’m trying to get the values as rows and put them in different <div>’s. here is what I wrote so far
<?php
$sql = "SELECT * FROM content";
$query = mysqli_query($db, $sql) or die (mysqli_error());
$contentDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$content_id = $row["id"];
$content_title= $row["title"];
$content_text = $row["text"];
$contentDisplay .= '<h1>'.$content_title.'</h1> <p>'.$content_text.'</p>' ."\n";
}
$row_cnt = $query->num_rows;
printf("Result set has %d rows.\n", $row_cnt);
?>
The row count gives 4 rows which is correct amount of rows.
In my html I have <?php echo $contentDisplay; ?> which puts out all 4 rows after each other, but I need to show the first row in my first <div>, the second row in my second <div> and so forth. thanks in advance
Update: I forgot to say that I have my <div>'s in the html part with different styles. all i need is the first row in one <div> (like on top of the page) and second row in another <div> (like on the bottom of the page) :)
Update2: here is the html code
<div class="content-top">
<section>
<h1></h1>
<p></p>
</section>
</div>
<div class="content-left">
<section>
<h1></h1>
<p></p>
</section>
</div>
<div class="content-center">
<section>
<h1></h1>
<p></p>
</section>
</div>
<div class="content-right">
<section>
<h1></h1>
<p></p>
</section>
</div>
i want the first row to be displayed in <div class="content-top"> the second row in <div class="content-left"> the third row in <div class="content-center"> and the fourth row in <div class="content-right">
<?php
$sql = "SELECT * FROM content";
$query = mysqli_query($db, $sql) or die (mysqli_error());
$rows = [];
while ($row = mysqli_fetch_array($query))
$rows[] = '<h1>'.$row['title'].'</h1> <p>'.$row['text'].'</p>' . "\n";
?>
<div class="content-top">
<section>
<?php echo $rows[0]; ?>
</section>
</div>
<div class="content-left">
<section>
<?php echo $rows[1]; ?>
</section>
</div>
<div class="content-center">
<section>
<?php echo $rows[2]; ?>
</section>
</div>
<div class="content-right">
<section>
<?php echo $rows[3]; ?>
</section>
</div>
$contentDisplay .= '<div><h1>'.$content_title.'</h1> <p>'.$content_text.'</p></div>' ."\n";
Just add divs for each row? :) This way, each row in the database will get a div.
Each row will be appended to the $contentDisplay variable, but since all you are doing is printing it, you can print the html directly.
I'm not sure why you are being downvoted, since you are asking a valid question with code that shows what you have tried so far.

php pass id into modal

I'm stuck again! So hopefully you awesome people can help me...
So far what I have is a search function that queries the database, and returns results, which works fine, and then the user can click one of the results, which takes them through to a new detailed page of what they clicked, for example a brand. Then on the detailed page, it returns all of that brands details (using $_GET['id']) and a new set of data, from a relational table, with a list of all the offers corresponding to that brand, which also works. But then I get stuck, I want the user to be able to click on each offer, and have the details of that offer load into a modal... I've tried using the $_GET['id'] for the offers id, but obviously, with it being on the same page (i presume), it passes the id of the brand / parent instead of the offer.
This is the code that calls back all the offers relating to the brand
$offers_sql = 'SELECT * FROM codes WHERE client_id LIKE :client_id AND CURDATE() between start AND expiry';
$offersq = $db->prepare($offers_sql);
$offers_params = array(':client_id' => $id);
$offersq->execute($offers_params);
$results = $offersq->fetchAll(PDO::FETCH_ASSOC);
if(count($results) < 1) {
$output = "<h4>no current offers available</h4>";
}
else {
foreach($results as $r) {
$title = $r['title'];
$code = $r['textcode'];
$offer_id = $r['id'];
$expiry = $r['expiry'];
$date = new DateTime($expiry);
$output .= '<h4>' . $title . '</h4><hr>';
}
}
} catch (PDOException $e) {
echo "failed to load offers";
}
?>
and this is the code i was using for the modal
require('inc/connect/config.php');
include('inc/result.php');
$page_title = "Title - " . $name . " Offers";
include('inc/style.php');
include('inc/header.php');
include('inc/offers.php');
?>
<!-- Intro Section -->
<section class="intro-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h3 class="navbar-fixed-top">Latest Deals</h3>
<h1><?php echo $name; ?></h1>
</div>
</div>
</div>
</section>
<section class="offer-section">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 col-lg-6 col-lg-offset-3">
<?php echo $output; ?>
</div>
</div>
</div>
</section>
<div class="md-modal md-effect-flip" id="offer">
<div class="md-content">
<h4><?php $offer = (int) $_GET['id'];
echo $offer ?></h4>
<button type="submit" class="modal-btn md-close navbar-fixed-bottom" value="submit"><p>close</p></button>
</div>
</div>
<?php include('inc/footer.php'); ?>
The code that returns the details of the brand is on a separate page, but i can include that if necessary.
What am i doing wrong? Please go easy on me, I am relatively new to php.
Thanks in advance
Kaylee
Make Changes, Where Output is declared in else condition. (Changes Done)
$output='<h4><a class="OfferIdClass" data-OfferID="<?echo $offer_id;?>" href="#offer" data-modal="offer" data-toggle="modal">'.$title.'</a></h4>';
// Add This to footer.php (Changes Done)
<div class="md-modal md-effect-flip" id="offer">
<div class="md-content">
</div>
</div>
//Add this below in that page, where you are clicking Modal.
//Changes Done
<script>
$('.OfferIdClass').click(function(){
var OfferID=$(this).attr('data-OfferID');
$.ajax({url:"Open-Offer.php?OfferID="+OfferID,cache:false,success:function(result){
$(".md-content").html(result); //Here, Changes Done
}});
});
</script>
//Create one Open-Offer.php page. (Changes Done)
Open-Offer.php
<?
extract($_GET);
<h4><?php $offer = (int) $_GET['id'];
echo $offer ?></h4>
<button type="submit" class="modal-btn md-close navbar-fixed-bottom" value="submit"><p>close</p></button>
?>

Render data from PHP DB query in HTML

I am a newbie to PHP but trying to learn it to enhance my programming skillset
So far i have the following PHP code in my page to return some data from my Database:
<?php
//code missing to retrieve my data
while($row = mysql_fetch_array($result))
{
echo '$row['Name']';
}
mysql_close($connection);
?>
This is working in that I can see the names from my database displayed on screen. I have seen as well that I can include html in the echo to format the data. However if I have the html code like below in a jQuery accordion outside my PHP code in the page - how can I dynamically place the Names in the specific h3 tags - so the first name in my table is Joe so that comes back in [0] element of array - is there a way I can reference this from my html code outside the php?
<div id="accordion">
<h3>Joe</h3>
<div>
<p>
Some blurb about Joe
</p>
</div>
<h3>Jane</h3>
<div>
<p>
Some blurb about Jane
</p>
</div>
<h3>John</h3>
<div>
<p>
Some Blurb about John.
</p>
</div>
</div>
Try something like this:
<?php while($row = mysql_fetch_array($result)) { ?>
<h3><?php echo $row['name']; ?></h3>
<div>
<p>Some blurb about Joe</p>
</div>
<?php } ?>
I'm assuming 'Some blurb about Joe' would also have to be replaced by a field in the DB, which you can accomplish in the same manner as the name.
#Gert is correct - the original mysql API is deprecated and should not be used anymore. Look into mysqli or PDO, instead.
add your html in while loop like this
<?php
//code missing to retrieve my data
while($row = mysql_fetch_array($result))
{
?>
<h3><?php echo $row['Name']?></h3>
<div>
<p>
Some blurb about <?php echo $row['Name']?>
</p>
</div>
<?php
}
mysql_close($connection);
?>
Like this :
<div id="accordion">
<?php
while($row = mysql_fetch_array($result))
{
<h3><?php echo $row['Name'] ?></h3>
<div>
<p>
Some blurb about Joe
</p>
</div>
} ?>
</div>

Categories