Placing mysql data into div which exists in html - php

I'm able to display mysql data from my database by simply echoing it in a blank div however I'd like to display it into an existing div style, by that I mean the style is already set.
I'm having trouble showing the right information in the write places and I could use abit of help with fixing up my code.
Here is the code for the html div :
<div class="[ col-xs-12 col-sm-offset-2 col-sm-8 ]" style="margin-top: 10px">
<ul class="event-list">
<li>
<time datetime="2014-08-22">
<span class="day">22</span>
<span class="month">AUG</span>
<span class="year">2014</span>
<span class="time">ALL DAY</span>
</time>
<img alt="Steakout" src="http://www.thedramateacher.com/wp-content/uploads/2014/04/vcaa-2014.jpg" />
<div class="info">
<h2 class="title">Night before VCAA</h2>
<p class="desc">Staying.</p>
</div>
<div class="social">
<ul>
<li class="facebook" style="width:33%;"><span class="fa fa-facebook"></span></li>
<li class="twitter" style="width:34%;"><span class="fa fa-twitter"></span></li>
<li class="google-plus" style="width:33%;"><span class="fa fa-google-plus"></span></li>
</ul>
</div>
</li>
In php I've decided to just recreate the whole div and just add the data I'd like to show into the div, it worked when I was just displaying unested divs but now that theres more it's gotten confusing.
Here is my Php code:
include('Specials.html');
$Category = 'Specials';
$query = $pdo->prepare("SELECT * FROM adsubm WHERE CATEGORY LIKE '%$Category%'");
$query->execute();
while($row = $query->fetch()) {
echo "<div class ='[ col-xs-12 col-sm-offset-2 col-sm-8 ] style='margin-top: 10px'>
<ul class='event-list'>
<div class='info'>
<div class='info'>
<h2 class='title'>".$row['ADTITLE'],
<time datetime>.$row['DATE'],
<p class='desc'> $row['DESCRIPTION']."</div></ul></div></div></h2></p>";
}
?>
I've been doing it piece by piece and testing each time but this time there are errors just popping up everywhere.
Kudos.

while($row = $query->fetch()) {
echo "<div class ='[ col-xs-12 col-sm-offset-2 col-sm-8 ] style='margin-top: 10px'>
<ul class='event-list'>
<div class='info'>
<div class='info'>
<h2 class='title'>".$row['ADTITLE'].
"<time datetime>".$row['DATE'].
"<p class='desc'>". $row['DESCRIPTION']."</div></ul></div></div></h2></p>";
}
some minor changes

Place this after your MySQL query.
<?php
while($row = $query->fetch()) {
?>
Put this where you want each row to show. You can easily place HTML around it.
<?php echo $row['ROWNAME']; ?>
Then this at the end of the document.
<?php
}
?>

Related

dynamic tab using php

Hi everyone I'm niubbie in php.I have a problem with tab. I would like the tabs on their click to show a different topic. All this using php and calling the db.
My DB:
giorno
pranzo
cena
lunedi
12:00
20:00
martedi
12:00
20:00
mercoledi
12:00
20:00
giovedi
12:00
20:00
venerdi
12:00
20:00
Days are represented by tabs and when I click on a different day I want it to show lunch and dinner of that particular day.
My code:
<section class="big-section bg-light-gray border-top border-color-medium-gray wow animate__fadeIn">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-12 text-center margin-six-bottom">
<h6 class="alt-font text-extra-dark-gray font-weight-500">Orari</h6>
</div>
</div>
<div class="row justify-content-center">
<div class="col-12 col-lg-10 tab-style-05">
<div class="tab-box">
<!-- start tab navigation -->
<ul class="nav nav-tabs margin-7-rem-bottom md-margin-5-rem-bottom xs-margin-15px-lr align-items-center justify-content-center font-weight-500 text-uppercase">
<?php
$sql = "SELECT * FROM orari_ristorante ";
$risultato = mysql_query($sql) or die(mysql_error()."<br>Impossibile eseguire l'interrogazione");
$i=0;
while ($riga = mysql_fetch_assoc($risultato)){
?>
<?php if($i == 0){?>
<li class="nav-item alt-font"><a class="nav-link active" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
<?php }else{?>
<li class="nav-item alt-font"><a class="nav-link" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
<?php }
$i++;
}?>
</ul>
<!-- end tab navigation -->
</div>
<div class="tab-content">
<!-- start tab content -->
<div class="tab-pane med-text fade in active show" id="tab-nine1">
<div class="panel-group accordion-event accordion-style-04" id="accordion1" data-active-icon="icon-feather-minus" data-inactive-icon="icon-feather-plus">
<!-- start accordion item -->
<div class="panel border-color-black-transparent">
<div class="panel-heading">
<?php
$sql = "SELECT pranzo,cena FROM orari_ristorante LIMIT 1";
$risultato = mysql_query($sql) or die(mysql_error()."<br>Impossibile eseguire l'interrogazione");
while ($riga = mysql_fetch_assoc($risultato)){
?>
<span class="panel-time">Pranzo</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['pranzo'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<span class="panel-time">Cena</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['cena'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<?php
}
?>
</div>
</div>
</div>
</div>
<!-- end tab content -->
</div>
</div>
</div>
</div>
</section>
My problem is that each tab shows all the rows and not the specific one for that day
My Problem
You need to ensure you are using unique ID's for your contents and using them in your href of the tab.
Reading your code it looks like each tab is created with the same ID
<li class="nav-item alt-font"><a class="nav-link active" href="#tab-nine1" data-toggle="tab"><?php echo $riga['giorno'];?></a></li>
I would echo out the unique id from the database eg.
href="#tab-<?echo $riga['id'];?>" (or whatever your unique column header is)
Ensure you also echo this out further down when the tab content is being created.
Based on what you are trying to accomplish, if you limit your results to one, you will always only show the first day in the db. Here's how I would change your second while loop.
<?php
$sql = "SELECT * FROM orari_ristorante";
$risultato = mysqli_query($conn, $sql);
$i = 0;
while ($riga = mysqli_fetch_assoc($risultato)){
if($i == 0){
$css = ""
}else{
$css = "display:none"
}
?>
<div class="giorno_tab <?php echo $riga['giorno'] ;?>" style="<?php echo $css ;?>">;
<span class="panel-time">Pranzo</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['pranzo'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
<span class="panel-time">Cena</span>
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1">
<div class="panel-title">
<span class="text-extra-dark-gray d-inline-block font-weight-500"><?php echo $riga['cena'] ;?></span>
</div>
</a>
<span class='prenota'>PRENOTA</span>
</div>
<?php
$i++;}
?>
</div>
It is not the solution, however you can build on top of that to accomplish what you are trying to do. Hopefully that somewhat helps.
Just to explain, I was adding $riga["giorno"] as an kind of ID in the class, however Revbo's answer would give a clearer code when it comes to an ID

After php form is sent, how do I edit the 'new' confirmation page?

PHP contact form is sent and displays a confirmation message: I need the div with the white background to be full column. If I put margins on the message, it breaks layout as pictured. I'm still wrapping my head around how the PHP logic's structure in terms of interactions, not sure where exactly to tweak it and fix the issue.
My code is structured as such:
<div id="whitebox" class="whitebox">
<div class="text-center orange-navbar">
<nav role="navigation">
<ul class="navcen nav nav-pills" >
<li role="presentation">Home</li>
<li role="presentation">Portfolio</li>
<li class="active" role="presentation">Contact</li>
</ul>
</nav>
</div>
<?php if(!empty($emailSent)): ?>
<div class="col-md-6 col-md-offset-3">
<div class="alert alert-success text-center"><?php echo $config->get('messages.success'); ?></div>
</div>
<?php else: ?>
<?php if(!empty($hasError)): ?>
<div class="col-md-5 col-md-offset-4">
<div class="alert alert-danger text-center"><?php echo $config->get('messages.error'); ?></div>
</div>
<?php endif; ?>
Add this to your css:
.whitebox {
height: 100vh;
}
This will give your whitebox div a height of 100% of your viewport.

Not able to align horizontal slider in a row

I have a horizontal carousel that is working fine, here is the code for it
Now i wish to fetch the data from database and display it that corousel. Following is the code that i used
<div class='row'>
<div class='col-xs-12'>
<div class="carousel slide media-carousel" id="media">
<div class="carousel-inner">
<div class="item active">
<div class="row">
<?php foreach($student as $student): ?>
<div class="col-md-3">
<a class="thumbnail" href="#"><?php echo $student->fullname;?></a>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
<a data-slide="prev" href="#media" class="left carousel-control">‹</a>
<a data-slide="next" href="#media" class="right carousel-control">›</a>
</div>
</div>
</div>
but the view is distorted and instead of all the slides sliding in one row, the view is coming like this
That's because unless the row is active, the other .item row gets the property display:none; If you were to remove the display:none; it should work as you want.
Create the class="row" inside the loop. Also keep in mind that the screen consists of 12 units only, so if you create a row of more than 12 units it will go to next line automatically. As you have created the loop that creates "col-md-3" for more than 4 times which sums more than 12, so it moves to next line.
For reference view this
As you have not given the php code, i am giving u sample of it
The array that you are getting divide it into a group of 4 (or as many as you want) like given below
$query = $this->db->get('student');
$r = $query->result();
$s = (array_chunk($r, 4));
return $s;
And then on the code you have given, change into following
<div class="carousel-inner">
<?php foreach($s as $key => $per_student): ?>
<?php if($key=='0'): ?>
<div class="item active">
<?php else: ?>
<div class="item ">
<?php endif; ?>
<div class="row">
<?php foreach($per_student as $student): ?>
<div class="col-md-3">
<a class="thumbnail" href="#"><?php echo $student->fullname;?></a>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endforeach; ?>
</div>

Applying PHP inside multiple divs

well, I have been trying to implement my PHP inside multiple divs but somehow my CSS gets messed up and the records start to display diagonally i.e first record displays correctly and then the rest of the records starts displaying from the end of their previous record (that can be viewed when scrolling right). Which is very annoying. What I'm trying to achieve is: To position my divs OR PHP in such a way that my CSS does not get disturbed, is this possible? Here's my PHP code for the particular data, any help would be appreciated.
<?php
$result1 = mysql_query("SELECT *from `movie_schedule`");
if(mysql_num_rows($result1))
{while($row2 = mysql_fetch_array($result1, MYSQL_BOTH))
{
?>
<div id="event" class="content-event">
<!-- container -->
<div class="container">
<h3>Show Times</h3>
<div class="event-grids">
<div class="col-md-3 event-grid">
<div class="pic"> </div>
<ul>
<li class="hedding"><?php print($row2['Movie_ID']); ?> <?php print($row2['Movie_Name']); ?></li>
<li class="date"><?php print($row2['Movie_Date']); ?></li>
</ul>
<div class="clearfix"> </div>
</div>
<div class="col-md-4 event-grid small-text">
<p><br><?php print($row2['Show_Time']); ?></p>
</div>
<div class="col-md-2 event-grid large-text">
<p class="text"><?php print($row2['Movie_Cost']); ?></p>
</div>
<div class="col-md-3 event-grid text-button">
<ul>
<li class="num"><?php print($row2['Movie_ID']); ?></li>
<li class="button yellow">Remove</li>
</ul><br><br>
<?php
}}
?>
</div>
</div>
</div>
It's not the CSS that's messing up. You're ending your loop before you close all of your elements properly inside a single block. You open the loop with a div, and you end it with an ul.
You can actually view the nested elements using a page inspector. In Chrome or Firefox, for example, this is achieved by right-clicking the page and selecting "Page inspector".
Try closing all your elements properly before closing your loop.
You are messing up with closing </div>
<?php
$result1 = mysql_query("SELECT *from `movie_schedule`");
if(mysql_num_rows($result1))
{
while($row2 = mysql_fetch_array($result1, MYSQL_BOTH))
{?>
<div id="event" class="content-event">
<div class="container">
<h3>Show Times</h3>
<div class="event-grids">
<div class="col-md-3 event-grid">
<div class="pic"> </div>
<ul>
<li class="hedding"><?php print($row2['Movie_ID']); ?> <?php print($row2['Movie_Name']); ?></li>
<li class="date"><?php print($row2['Movie_Date']); ?></li>
</ul>
<div class="clearfix"> </div>
</div>
<div class="col-md-4 event-grid small-text">
<p><br><?php print($row2['Show_Time']); ?></p>
</div>
<div class="col-md-2 event-grid large-text">
<p class="text"><?php print($row2['Movie_Cost']); ?></p>
</div>
<div class="col-md-3 event-grid text-button">
<ul>
<li class="num"><?php print($row2['Movie_ID']); ?></li>
<li class="button yellow">Remove</li>
</ul>
<br><br>
</div>
</div>
</div>
</div>
<?php}}?>

Display MySql Data Using Div

How to display images from mysql database, specifically two images in a row. I've read many articles in stack overflow, all of them discussed using the table tag. But I couldn't find any article using div.
Here is my SQL code which is not completely correct.(displays images, but not in correct order) :
$result=mysql_query("SELECT * FROM images WHERE tag='$tag' ");
while($info=mysql_fetch_array($result))
{
if($count==2) //two images per row
{
print "</div>";
$count = 0;
}
if($count==0)
print '<div class="row"><div class="col-md-6 col-sm-6 gallery-display">';
?>
<figure>
<a href="first-image.php">
<img src="1.jpg" alt="Texture Paper" class="display-image">
</a>
<a href="first-image.php" class="figcaption">
<h3>Texture Paper</h3>
</a>
</figure>
<?php
$count++;
print '</div>';
}
if($count>0)
print "";
?>
This How Code should come !
<div class="row">
<div class="col-md-4 col-sm-4 gallery-display">
<figure>
<a href="first-image.php">
<img src="1.jpg" alt="Texture Paper" class="display-image">
</a>
<a href="first-image.php" class="figcaption">
<h3>Texture Paper</h3>
</a>
</figure>
<!--figure-->
</div>
<div class="col-md-4 col-sm-4 gallery-display">
<figure>
<a href="sec-image.php">
<img src="2..jpg" alt="Photo (:" class="display-image">
</a>
<a href="sec-image.php" class="figcaption">
<h3>Photo Caption</h3>
</a>
</figure>
</div>
<!--.gallery-display-->
<div class="row">
<div class="col-md-4 col-sm-4 gallery-display">
..........loop code continues.......
It looks like you want to use array_chunk. You might want to check around before posting this kind of stuff, because this appears to be a duplicate/very similar to
PHP: display entries from Database in groups of five?

Categories