I am trying to get my div card to stay right next to my other card board and also dont get strached out. The first one works perfectly, but I dont know how to place the next one right next to the first one...
$sql = "SELECT * FROM beitrag WHERE beitrag_id=97 OR beitrag_id=98";
$res = mysqli_query($db, $sql) or die(mysqli_error());
if(mysqli_num_rows($res) > 0) {
$beitrag = "
<div class='pagecontainer'>
<div class='container'>
<div class='jumbotron p- p-md-5 text-white rounded bg-dark'>
<div class='col-md-6 px-0'>
<h1 class='display-4 font-italic'>Student, Azubi, FSJler, Schüler...?</h1>
<p class='lead my-3'>Tauschen Sie sich noch heute mit tausenden Gleichgesinnten über Ihre finanzielle Planung aus!</p>
<p class='lead mb-0'><a href='beitraege.php' class='text-white font-weight-bold'>Ab zu den Beitraegen!</a></p>
</div>
</div>
<div class='row mb-2'>";
while ($row = mysqli_fetch_assoc($res)) {
$beitrag_id = $row['beitrag_id'];
$titel = $row['titel'];
$miete = $row['miete'];
$einkauf = $row['einkauf'];
$freizeit = $row['freizeit'];
$sonstiges = $row['sonstiges'];
$g_kosten = $row['g_kosten'];
$p_text = $row['p_text'];
$beitrag .="
<div class='col-md-6'>
<div class='card' style=''>
<div class='card-body'>
<h4 class='card-title'>$titel</h4>
<p class='card-text'>$p_text</p>
<a href='siehe_beitrag.php?pid=$beitrag_id' class='btn btn-primary'>Mehr erfahren</a>
</div>
</div>
";
$beitrag .="
</div>
</div>
</div>
</div>
";
}
echo $beitrag;
}
Try with this code istead of yours.
$sql = "SELECT * FROM beitrag WHERE beitrag_id=97 OR beitrag_id=98";
$res = mysqli_query($db, $sql) or die(mysqli_error());
if(mysqli_num_rows($res) > 0) {
$beitrag = "
<div class='pagecontainer'>
<div class='container'>
<div class='jumbotron p- p-md-5 text-white rounded bg-dark'>
<div class='col-md-6 px-0'>
<h1 class='display-4 font-italic'>Student, Azubi, FSJler, Schüler...?</h1>
<p class='lead my-3'>Tauschen Sie sich noch heute mit tausenden Gleichgesinnten über Ihre finanzielle Planung aus!</p>
<p class='lead mb-0'><a href='beitraege.php' class='text-white font-weight-bold'>Ab zu den Beitraegen!</a></p>
</div>
</div>
<div class='row mb-2'>";
while ($row = mysqli_fetch_assoc($res)) {
$beitrag_id = $row['beitrag_id'];
$titel = $row['titel'];
$miete = $row['miete'];
$einkauf = $row['einkauf'];
$freizeit = $row['freizeit'];
$sonstiges = $row['sonstiges'];
$g_kosten = $row['g_kosten'];
$p_text = $row['p_text'];
$beitrag .="
<div class='col-md-6'>
<div class='card' style=''>
<div class='card-body'>
<h4 class='card-title'>$titel</h4>
<p class='card-text'>$p_text</p>
<a href='siehe_beitrag.php?pid=$beitrag_id' class='btn btn-primary'>Mehr erfahren</a>
</div>
</div>
</div>
";
//you fault here. You should have the loop on this card only.
}
//you fault here. one </div> goes down bottom.
$beitrag .="
</div>
</div>
</div>
";
echo $beitrag;
}
Related
So basically i have a Project where i have to make our Menu Order Website better, for that i want to Include a Weekly rotating menu where the Users can order, i have the whole website done including the Admin panels yet i cant figure out how to create a rotating website, for now i have all Menus included in the Main Website i tried it with Wordpress code, which i then realised isnt supported in basic php... the only code i find is from 2014 and i dont have a clue where to include it in my code as im a Newbie :) What would be cool is like a small dropdown button where you can show the next weeks menu too
Main Site section to order menus
<!-- fOOD sEARCH Section Starts Here -->
<section class="food-search text-center">
<div class="container">
<form action="<?php echo SITEURL; ?>food-search.php" method="POST">
<input type="search" name="search" placeholder="Search for Food.." required>
<input type="submit" name="submit" value="Search" class="btn btn-primary">
</form>
</div>
</section>
<!-- fOOD sEARCH Section Ends Here -->
<!-- fOOD MEnu Section Starts Here -->
<section class="food-menu">
<div class="container">
<h2 class="text-center">Mama Bringts Menüs</h2>
<?php
//Zeigt Menüs an die auf Active gesetzt sind
$sql ="SELECT * FROM tbl_food WHERE active='Yes'";
//Query ausführen
$res = mysqli_query($conn, $sql);
//Rows zählen
$count= mysqli_num_rows($res);
//Schauen ob die Menüs verfügbar (Active) sind
if($count>0)
{
//Verfügbar
while($row=mysqli_fetch_assoc($res))
{
//Werte auslesen
$id = $row['id'];
$title = $row['title'];
$description = $row['description'];
$price = $row['price'];
$image_name =$row['image_name'];
?>
<div class="food-menu-box">
<div class="food-menu-img">
<?php
//Bild verfügbar oder nicht
if($image_name=="")
{
//Bild nicht verfügbar
echo "<div class='error'>Das Bild ist nicht verfügbar</div>";
}
else
{
//Bild verfügbar
?>
<img src="<?php echo SITEURL; ?>images/food/<?php echo $image_name; ?>" alt="Chicke Hawain Pizza" class="img-responsive img-curve">
<?php
}
?>
</div>
<div class="food-menu-desc">
<h4><?php echo $title; ?></h4>
<p class="food-price"><?php echo $price; ?></p>
<p class="food-detail">
<?php echo $description; ?>
</p>
<br>
Jetzt Bestellen
</div>
</div>
<?php
}
}
else
{
//Nicht verfügbar
echo "<div class='error'>Das Menü wurde nicht gefunden!</div>";
}
?>
<div class="clearfix"></div>
</div>
</section>
<!-- fOOD Menu Section Ends Here -->
<?php include('partials-front/footer.php')?>
Admin Site to Manage the Menus
<!-- Main Content Section -->
<div class="main-content">
<div class="wrapper">
<h1>Administrator Verwaltung</h1>
<br /><br /><br />
<?php
if(isset($_SESSION['add']))
{
echo $_SESSION['add']; //Zeigt Session Nachricht an
unset($_SESSION['add']); //Entfernt Session Nachricht
}
if(isset($_SESSION['delete']))
{
Echo $_SESSION['delete'];
unset($_SESSION['delete']);
}
if(isset($_SESSION['update']))
{
echo $_SESSION['update'];
unset($_SESSION['update']);
}
if(isset($_SESSION['user-not-found']))
{
echo $_SESSION['user-not-found'];
unset($_SESSION['user-not-found']);
}
if(isset($_SESSION['pwd-not-match']))
{
echo $_SESSION['pwd-not-match'];
unset($_SESSION['pwd-not-match']);
}
if(isset($_SESSION['change-pwd']))
{
echo $_SESSION['change-pwd'];
unset($_SESSION['change-pwd']);
}
?>
<br><br><br>
<!-- Button to add Admin -->
Add Admin
<br/><br/><br/>
<table class="tbl-full">
<tr>
<th>S.N.</th>
<th>Full Name</th>
<th>Username</th>
<th>Actions</th>
</tr>
<?php
//Fügt alle Admins zum Table hinzu
$sql = "SELECT * FROM tbl_admin";
//Führt die Query aus
$res = mysqli_query($conn, $sql);
//Schaut nach ob die Query ausgeführt wurde oder nicht
if($res==TRUE)
{
// Zählt die Zeilen in der Datenbank um zu schauen ob wir Daten in der Bank haben oder nicht
$count = mysqli_num_rows($res); // Holt sich alle Zeilen der Datenbank
$sn=1; //Created die Variablen und Weisst die den Admins zu
//Checkt die Anzahl von Zeilen
if($count>0)
{
//Haben Daten in Datenbank
while($rows=mysqli_fetch_assoc($res))
{
//Benutzen While loop um die Daten in der Datenbank zu bekommen
//Der Loop lauft so lang wir Daten haben
//Individuelle Daten ziehen
$id=$rows['id'];
$full_name=$rows['full_name'];
$username=$rows['username'];
//Values im Table anzeigen
?>
<tr>
<td><?php echo $sn++; ?></td>
<td><?php echo $full_name; ?></td>
<td><?php echo $username; ?></td>
<td>
Change Password
<a href="<?php echo SITEURL; ?>admin/update-admin.php?id=<?php echo $id; ?>" class="btn-secondary" >Update Admin</a>
<a href="<?php echo SITEURL; ?>admin/delete-admin.php?id=<?php echo $id; ?>" class="btn-danger" >Delete Admin</a>
</td>
</tr>
<?php
}
}
else
{
//Wir haben keine Daten in der Datenbank
}
}
?>
</table>
<!-- Button Ende -->
</div>
Has been fixed, used this code for Sorting and switching through Menus
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name='kwlist'>
<option value="">--- KW wählen ---</option>
<?php
$sql = "SELECT KW, Year from tbl_food ORDER BY `tbl_food`.`Year`, `tbl_food`.`KW` ASC LIMIT 3;";
$res = mysqli_query($conn, $sql);
$count= mysqli_num_rows($res);
if($count>0)
{
while($row=mysqli_fetch_assoc($res))
{
$KW = $row['KW'];
$year = $row['Year'];
echo '<option value="'.$KW.'/'.$year.'">'.$KW.' / '.$year.'</option>';
}
}
?>
</select>
<input type="submit" name="Submit" value="Auswählen" />
</form>
</body>
</html>
<?php
//Sortiert Menüs nach KW max 1 Woche vor und 1 Woche rückblickend
if(isset($_POST['kwlist']) && $_POST['kwlist'] != "")
{
$kwyear = explode("/", $_POST['kwlist']);
//echo $kwyear[0]; // KW
//echo $kwyear[1]; // Jahr
$sql = "SELECT * FROM tbl_food WHERE `KW` =$kwyear[0] AND `Year` =$kwyear[1]";
}
else
{
$actual_kw = date('W');
$actual_year = date('Y');
$sql = "SELECT * FROM tbl_food WHERE `KW` = $actual_kw AND `Year` = $actual_year";
}
I have a Problem:
I coded a whole gallery with bootstrap and in this gallery are gaps. There are 100 pictures on 7 pages and instead of going down in one picture block it has gaps between it. This follows no obvious order.
Here is a picture:
So I wanted to take the whole col-md etc and picture container away and make my own columns. So that it works properly, but my solution from the internet doesn't work... I think it must be a problem with PHP that it is in a For loop and not in pure HTML like in the solutions. But I don't know how to solve it.
Here is the PHP code before:
<?php
//require_once("galerie-config.php");
if (!isset($_GET['pageindex'])) {
$_GET['pageindex'] = "1";
}....
<script type='text/javascript' src='../js/Bateaux/jquery/jquery.js'></script>
<script type='text/javascript' src='../js/Bateaux/jquery/jquery-migrate.min.js'></script>
<script type='text/javascript' src='../revslider/public/assets/js/jquery.themepunch.tools.min.js'></script>
<script type='text/javascript' src='../revslider/public/assets/js/jquery.themepunch.revolution.min.js'></script>
<script type='text/javascript'>
/* <![CDATA[ */
var BateauxOptions = {"ajax_url":"../js/admin-ajax.html"};
/* ]]> */
</script>
<script type='text/javascript'>
/* <![CDATA[ */
var mejsL10n = {
"language": "en-US",
"strings": {
"Close": "Close",
"Fullscreen": "Fullscreen",
"Download File": "Download File",
"Download Video": "Download Video",
"Play\/Pause": "Play\/Pause",
"Mute Toggle": "Mute Toggle",
"None": "None",
"Turn off Fullscreen": "Turn off Fullscreen",
"Go Fullscreen": "Go Fullscreen",
"Unmute": "Unmute",
"Mute": "Mute",
"Captions\/Subtitles": "Captions\/Subtitles"
}
};
var _wpmejsSettings = {
"pluginPath": "../js\/mediaelement\/"
};
/* ]]> */
</script>
<script type='text/javascript' src='../js/Bateaux/hoverIntent.min.js'></script>
<script type='text/javascript' src='../js/Bateaux/jquery/ui/widget.min.js'></script>
<script type='text/javascript' src='../js/Bateaux/main-vendors.min.js'></script>
<script type='text/javascript' src='../js/Bateaux/main.min.js'></script>
<!-- INNER BANNER STARTS
========================================================================= -->
<div class="inner-banner" style="background-color:#fff;">
<div class="container">
<ol class="breadcrumb">
<li>Home</li>
<li>Referenzen</li>
<li class="active">Galerie</li>
</ol>
<h1>Galerie</h1>
</div>
</div>
<!-- /. INNER BANNER STARTS
========================================================================= -->
<!-- PORTFOLIO STARTS
========================================================================= -->
**<div class="container contents portfolio">
<div class="row no-gutter-6">
<?php
require_once("dbh.php");
$numPicturesPerPage = 20;
//$seiten = [0,1,2,3,4,5,6,7,8,9,10];
global $pageIndex;
$pageIndex = 1;
if (isset($_GET['pageindex'])) {
$pageIndex = $_GET['pageindex'];
}
$bildauswahl = $numPicturesPerPage * ($pageIndex -1);
$sql = "SELECT * FROM galeriebilder LIMIT $bildauswahl,$numPicturesPerPage";
$rows = $dbh->query($sql);
$imgPathNames = [];
$i = 0;
foreach ($rows as $row) {
//for ($i=0;$i<$numPicturesPerPage;$i++) {
$bildcode = $row['bildcode'];
//array_push($imgPathNames, $bildcode);
$i++;
echo "<!-- Picture Starts -->";
***echo "<div class='col-lg-6 col-md-6 col-sm-6'>";
echo "<div class='picture'>";
echo "<img id='aquarium-galerie-" . $i . "' src='../images/galerie/". "$bildcode" . "'" . " onclick='alert(\"" . $bildcode . "\")' class='img-responsive editable' alt='' />";
echo "</div>";
echo "</div>";
//}***
?>
<!-- Picture Ends -->
<?php
}
?>
</div>
<div class="row">
<!-- Picture Starts -->
<?php
global $numPages;
$sql ="SELECT count(bild_id) FROM galeriebilder";
$rows = $dbh->query($sql);
foreach ($rows as $row){
global $numPictures;
$numPictures = $row[0];
}
$biggerThan = $numPictures % $numPicturesPerPage;
$numPages = intval(floor($numPictures / $numPicturesPerPage));
if ($biggerThan > 0) {
$numPages++;
}
if (preg_match("/d+/", $pageIndex, $matches)) { $pageIndex = $matches[0]; } // Filtert die Zahl aus z.B. 2.php heraus
function navSeiten($aktuell,$gesamt) {
$pageIndex = $_GET['pageindex'];
$next = $aktuell + 1;
$previous = $aktuell - 1;
$ausgabe = '<ul class="pager">';
if ($aktuell <= 3 ) {
$seiten = array(1,2,3,4,5);
}else if ($aktuell == $gesamt -3 ) {
$seiten = array($aktuell -2 ,$aktuell-1 ,$aktuell , $aktuell +1 , $aktuell +2);
}else if ($aktuell >= $gesamt -3 ) {
$seiten = array($gesamt -4 , $gesamt -3, $gesamt -2 , $gesamt -1, $gesamt );
} else {
$seiten = array( $aktuell -2 ,$aktuell-1 ,$aktuell , $aktuell +1 , $aktuell +2);
}
//echo ($pageIndex);
?>
<li class="previous" style="<?php
if ($pageIndex == "1" ) { echo "display:none ";} ?>" >
<a href="galerie.php?pageindex=' . $previous . '" aria-label="Previous">
<span aria-hidden="true"></span>
</a>
</li>
<?php
foreach ($seiten as $seite) {
if ($seite == $pageIndex) {
$ausgabe .= '<li class="active">' . $seite . '</li>';
} else {
$ausgabe .='<li>' . $seite . '</li>';
}
}
?><li class="next" style="
<?php
/*$sql ="SELECT count(bild_id) FROM galeriebilder";
$rows = $dbh->query($sql);
foreach ($rows as $row) {
$numPictures = $row[0];
}*/
$numPicturesPerPage = 20;
$numPages = intval(floor($numPictures / $numPicturesPerPage));
if ($pageIndex == $numPages ) { echo "display:none"; }
?>" >
<a href="galerie.php?pageindex=' . $next . '" aria-label="Next">
<span aria-hidden="true"></span>
</a>
</li>
<?php
//echo $numPages;
echo $numPictures;
$ausgabe .= '</ul>';
return $ausgabe;
}
?>
<div class="col-lg-12 no-gutter-12 pagging">
<?php echo navSeiten($pageIndex,$numPages) ?> <!-- Dies ist der Funktionsaufruf der Funktion die die komplette Leiste der Seitenaufrufe-->
</div>
</div>
</div>
<!-- /. PORTFOLIO ENDS**
========================================================================= -->
<!-- FOOTER STARTS
========================================================================= -->
<footer class="parallax-1">
<!-- Social Media Starts -->
<div class="social-media transparent-black-bg" style="background-color:#000;">
<div class="container">
<div class="row">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-6">
<div class="caption">Facebook</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-6">
<div class="caption">Youtube</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-6">
<div class="caption">Instagram</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-6">
<div class="caption">Google+</div>
</div>
</div>
</div>
</div>
<!-- Social Media Ends -->
<!-- Contact Info Starts -->
<div class="contact-info" style="background-color:#313131;">
<div class="container">
<div class="row">
<!-- Address Starts -->
<div class="col-lg-3 col-md-3 col-sm-3 address">
<div class="footer-logo"><img src="../images/Startseite/Logo-Footer.png" class="img-responsive" alt="Logo von Biological Aqua Dreams (eine Koralle)" style="margin-left:0;"></div>
<address>
<strong>KONRAD-HAUSSMANN-WEG 6<br>
D-73614 SCHORNDORF</strong>
<div class="phone">+49 176 6316 1653</div>
<div>INFO#BIOLOGICAL-AQUA-DREAMS.COM</div>
</address>
<div class="about">Sie haben Fragen? Kontaktieren Sie uns einfach telefonisch oder per Email.</div>
</div>
<!-- Address Ends -->
<!-- Blog Posts Starts -->
<div class="col-lg-4 col-md-4 col-sm-4 latest-posts">
<h1>ALLES AUF EINEN BLICK</h1>
<div class="post">
<h2>Unsere Leistungen </h2>
<div class="info"><span class="user">Erfahren Sie mehr über uns</span></div>
</div>
<div class="post">
<h2>Wartung und Reparatur</h2>
<div class="info"><span class="user">Wir sind für Sie da</span></div>
</div>
</div>
<!-- Blog Posts Ends -->
<!-- Get in Touch Starts -->
<div class="col-lg-5 col-md-5 col-sm-5 get-in-touch">
<h1>KONTAKT AUFNEHMEN</h1>
<form action='../process.php' method='post' name='ContactForm' id='ContactForm'>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="Email *">
</div>
<textarea rows="5" class="form-control" name="comment" placeholder="Nachricht *"></textarea>
<div id='message_post'></div>
<input class="btn btn-default" type='submit' value='SENDEN' name='submitf' id="submitf" style="outline:none;">
</form>
</div>
<!-- Get in Touch Ends -->
</div>
</div>
</div>
<!-- Contact Info Ends -->
<!-- Copyright Starts -->
<div class="copyright light-grey-bg">
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-8 col-sm-8">© 2018 BIOLOGICAL AQUA DREAMS |
DATENSCHUTZ | IMPRESSUM</div>
<div class="col-lg-4 col-md-4 col-sm-4 created-by">Created by Crew Ad</div>
</div>
</div>
</div>
<!-- Copyright Starts -->
</footer>
....
And here after my solution:
<div class="container contents portfolio">
<div class="row no-gutter-6">
<?php
require_once("dbh.php");
$numPicturesPerPage = 20;
//$seiten = [0,1,2,3,4,5,6,7,8,9,10];
global $pageIndex;
$pageIndex = 1;
if (isset($_GET['pageindex'])) {
$pageIndex = $_GET['pageindex'];
}
$bildauswahl = $numPicturesPerPage * ($pageIndex -1);
$sql = "SELECT * FROM galeriebilder LIMIT $bildauswahl,$numPicturesPerPage";
$rows = $dbh->query($sql);
$imgPathNames = [];
$i = 0;
foreach ($rows as $row) {
//for ($i=0;$i<$numPicturesPerPage;$i++) {
$bildcode = $row['bildcode'];
//array_push($imgPathNames, $bildcode);
$i++;
echo "<!-- Picture Starts -->";
//echo "<div class='col-lg-6 col-md-6 col-sm-6'>";
echo "<div class='picture'>";
echo "<figure><img id='aquarium-galerie-" . $i . "' src='../images/galerie/". "$bildcode" .
"'" . "width='750px' height='500px' onclick='alert(\"" . $bildcode .
"\")' class='img-responsive pic editable' alt='' /></figure>";
echo "</div>";
//echo "</div>";
//}
?>
<!-- Picture Ends -->
<?php
}
?>
</div>
<div class="row">
<!-- Picture Starts -->
<?php
global $numPages;
$sql ="SELECT count(bild_id) FROM galeriebilder";
$rows = $dbh->query($sql);
foreach ($rows as $row){
global $numPictures;
$numPictures = $row[0];
}
$biggerThan = $numPictures % $numPicturesPerPage;
$numPages = intval(floor($numPictures / $numPicturesPerPage));
if ($biggerThan > 0) {
$numPages++;
}
if (preg_match("/d+/", $pageIndex, $matches)) { $pageIndex = $matches[0]; } // Filtert die Zahl aus z.B. 2.php heraus
function navSeiten($aktuell,$gesamt) {
$pageIndex = $_GET['pageindex'];
$next = $aktuell + 1;
$previous = $aktuell - 1;
$ausgabe = '<ul class="pager">';
if ($aktuell <= 3 ) {
$seiten = array(1,2,3,4,5);
}else if ($aktuell == $gesamt -3 ) {
$seiten = array($aktuell -2 ,$aktuell-1 ,$aktuell , $aktuell +1 , $aktuell +2);
}else if ($aktuell >= $gesamt -3 ) {
$seiten = array($gesamt -4 , $gesamt -3, $gesamt -2 , $gesamt -1, $gesamt );
} else {
$seiten = array( $aktuell -2 ,$aktuell-1 ,$aktuell , $aktuell +1 , $aktuell +2);
}
//echo ($pageIndex);
?>
<li class="previous" style="<?php
if ($pageIndex == "1" ) { echo "display:none ";} ?>" >
<a href="galerie.php?pageindex=' . $previous . '" aria-label="Previous">
<span aria-hidden="true"></span>
</a>
</li>
<?php
foreach ($seiten as $seite) {
if ($seite == $pageIndex) {
$ausgabe .= '<li class="active">' . $seite . '</li>';
} else {
$ausgabe .='<li>' . $seite . '</li>';
}
}
?><li class="next" style="
<?php
/*$sql ="SELECT count(bild_id) FROM galeriebilder";
$rows = $dbh->query($sql);
foreach ($rows as $row) {
$numPictures = $row[0];
}*/
$numPicturesPerPage = 20;
$numPages = intval(floor($numPictures / $numPicturesPerPage));
if ($pageIndex == $numPages ) { echo "display:none"; }
?>" >
<a href="galerie.php?pageindex=' . $next . '" aria-label="Next">
<span aria-hidden="true"></span>
</a>
</li>
<?php
//echo $numPages;
echo $numPictures;
$ausgabe .= '</ul>';
return $ausgabe;
}
?>
<div class="col-lg-12 no-gutter-12 pagging">
<?php echo navSeiten($pageIndex,$numPages) ?> <!-- Dies ist der Funktionsaufruf der Funktion die die komplette Leiste der Seitenaufrufe-->
</div>
</div>
</div>
Here is the CSS Code:
.picture {
clear:both;
}
.pic {
//float: left;
width:50%;
display:block;
}
figure {
display: table-cell;
text-align: center;
}
Sorry that it's now a mix of all solutions I found on the internet. I didn't changed it already.
I hope you can help me.
With kindly greetings Lukas Stetter
I am having the weirdest time with the html output. the first output works fine if you look at //start gallery row that is where my problems begin.
This is how the output should look
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
<img class='img-responsive' src='cdn/assets/gallery/1.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/3.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/2.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/4.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/5.jpg'>
</div>
</div>
</div>
at the start of // gallery when I view source this is the out put
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
<img class='img-responsive' src='cdn/assets/gallery/1.jpg'></div>
</div>
</div>
<img class='img-responsive' src='cdn/assets/gallery/3.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/2.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/4.jpg'>
<img class='img-responsive' src='cdn/assets/gallery/5.jpg'>
but no matter where I put the last output DIV it causes issues
<?php
$stmt = $db->prepare("my query");
$stmt->execute();
$result = $stmt->get_result();
$output = "";
$checker = [];
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && ! empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage= "avatar.jpg";
}
if(!in_array($row['ID'], $checker)) {
$output .= "
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>";
//End of info row
$output .="<br /><br /><br />";
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
";
}
foreach ($GalleryImage as $img){
//Display this row as many times as needed by data in this row.
$output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
}
$output .= "
</div>
</div>
</div>";
// End gallery row
array_push( $checker, $row['ID']);
}
$output .= "</div>";
echo $output;
?>
sql
$stmt = $db->prepare("
SELECT U.ID,
U.FullName,
U.Email,
U.JobTitle,
U.Bio,
U.Photo, G.GalleryImage
FROM users U
LEFT join gallery G
ON U.ID = G.ID
");
$stmt->execute();
$result = $stmt->get_result();
Ok, so I believe the best course of action is to loop through your $result and filter out all the repeated values as well as assigning images to an array with the row['ID'] as the key and then loop through them after CHECK IT!
$checker = array();
$profileArray = array();
while ($row = mysqli_fetch_assoc($result))
{
if($row['GalleryImage'])
{
$profileArray[$row['ID']]['GalleryImages'][] = $row['GalleryImage'];
}
if(!in_array($row['ID'], $checker))
{
while (list ($key, $value) = each($row))
{
if($key != 'GalleryImage')
{
$profileArray[$row['ID']][$key] = $value;
}
}
$checker[] = $row['ID'];
}
}
foreach ($profileArray as $row)
{
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleyImages = $row['GalleryImages'];
if (isset($Photo) && !empty($Photo))
{
$ProfileImage = "$Photo";
}
else
{
$ProfileImage = "avatar.jpg";
}
$output .= "
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>";
//End of info row
$output .= "<br /><br /><br />";
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>";
if(!$GalleyImages)
{
foreach ($GalleyImages as $img)
{
//Display this row as many times as needed by data in this row.
$output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
}
}
else
{
$output .= "HTML THAT YOU WANNA DISPLAY instead of images";
}
$output .= "
</div>
</div>
</div>
</div>";
}
echo $output;
Ok, first of all it is always good to format your code properly so you don't make these mistake.
Your first output is missing a closing div
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
</div> <!-- This was missing-->
lastly you had close your if statement to quickly around the below code:
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
";
} // CLOSED AT THE WRONG SPOT
Try the below:
<?php
$stmt = $db->prepare("my query");
$stmt->execute();
$result = $stmt->get_result();
$output = "";
$checker = [];
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && ! empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage= "avatar.jpg";
}
if(!in_array($row['ID'], $checker)) {
$output .= "
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/$ProfileImage'>
</div>
<div class='col-md-6'>
<strong>$FullName<br>$JobTitle</strong>
<br>
<p>$Bio</p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
</div> <!-- This was missing-->
";
//End of info row
$output .="<br /><br /><br />";
//Start Gallery Row
$output .= "
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
";
foreach ($GalleryImage as $img) {
//Display this row as many times as needed by data in this row.
$output .= "<img class='img-responsive' src='cdn/assets/gallery/$img'>";
}
$output .= "
</div>
</div>
</div>
";
// End gallery row
array_push( $checker, $row['ID']);
}
}
$output .= "</div>";
echo $output;
?>
Most of the time try to separate your PHP from HTML that you can see errors easily.
$stmt = $db->prepare("query");
$stmt->execute();
$result = $stmt->get_result();
$output = "";
$checker = [];
while ($row = mysqli_fetch_assoc($result)) {
$ID = $row['ID'];
$FullName = $row['FullName'];
$Email = $row['Email'];
$JobTitle = $row['JobTitle'];
$Bio = $row['Bio'];
$Photo = $row['Photo'];
$GalleryImage = explode(',', $row['GalleryImage']);
if (isset($Photo) && !empty($Photo)) {
$ProfileImage = "$Photo";
} else {
$ProfileImage = "avatar.jpg";
}
if (!in_array($row['ID'], $checker)) : ?>
<div class='container yep team-wrap'>
<div class='row'>
<div class='col-md-6'>
<img class='img-responsive' src='cdn/assets/artist/<?php echo $ProfileImage; ?>'>
</div>
<div class='col-md-6'>
<strong><?php echo $FullName; ?><br><?php echo $JobTitle; ?></strong>
<br>
<p><?php echo $Bio; ?></p>
<a href='mailto:$Email' class='btn btn-info'>Contact Me</a>
</div>
</div>
<!-- End of info row-->
<br/><br/><br/>
<!-- Start Gallery Row-->
<div class='row'>
<div class='col-md-12'>
<div id='gallery-slider' class='slider responsive'>
<!-- Display this row as many times as needed by data in this row.-->
<?php foreach ($GalleryImage as $img) : ?>
<img class='img-responsive' src='cdn/assets/gallery/<?php echo $img; ?>'>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<!-- // End gallery row-->
<?php array_push($checker, $row['ID']); endif;
}
?
Example output
Im a PHP newbie. I am creating a jobs website and my search function tells me when there is no result but if there is, it displays ALL the jobs I have entered on the database. Please assist, I have tried everything.
here is my code:
<?php
if(isset($_POST['submit']))
{
$search = $_POST['keyword'];
$query = "SELECT * FROM jobs WHERE job_tags LIKE '%$search%'";
$search_query = mysqli_query($connection, $query);
if(!$search_query) {
die ("query failed" . mysqli_error($connection));
}
$count = mysqli_num_rows($search_query);
if($count == 0){
echo "<h3> NO RESULT</h3>";
}else{
$query = "SELECT * FROM jobs";
$job_display = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($job_display)){
$job_title = $row['job_title'];
$employer = $row['employer'];
$job_date = $row['job_date'];
$job_logo = $row['job_logo'];
$job_desc = $row['job_desc'];
?>
<div class="row">
<div>
<div class="media img-responsive">
<div class="media-left media-middle">
<a href="#">
<img class="media-object" src="images/<?php echo $job_logo; ?>" class="img-responsive" alt="Absa Insurance Logo">
</a>
</div>
<div class="media-body">
<h4 class="media-heading"><span class="job-tittle"><?php echo "{$job_title}";?> </span>(<i class="glyphicon glyphicon-map-marker"> </i>Gauteng, <span class="type blue"> Short-Term Insurance</span>)</h4>
<P>
<?php echo $job_desc;?>
... <i class="glyphicon glyphicon-plus"> </i> Read More</P>
</div>
<div class=" media-right media-middle job-location">
<p> <?php echo $job_date;?> </p>
</div>
</div>
</div>
</div>
<?php }
}
}
?>
here is the Form
<form class=" form-inline" action="search.php" method="post">
<div class="form-group">
<input type="text" name="keyword" class="form-control" placeholder="Job Key Word">
</div>
</form>
Please let me know if you need more information.
you need to remove this line or just filter here
$query = "SELECT * FROM jobs";
In first query You are looking for only selected records
$query = "SELECT * FROM jobs WHERE job_tags LIKE '%$search%'";
$search_query = mysqli_query($connection, $query);
If it find something You search one more time with
$query = "SELECT * FROM jobs";
You don't put WHERE in this query.
<div class="row">
<?php
require 'config.php';
$query = "SELECT * FROM `posts` ORDER BY `id` DESC LIMIT 8";
$do = mysqli_query($con, $query) ;
while ($result = mysqli_fetch_array($do)){
$query="SELECT * FROM `lang` where id='$result[langid]'";
$do=mysqli_query($con,$query);
$lang=mysqli_fetch_array($do);
$query="SELECT * FROM `users` where id='$result[userid]'";
$do=mysqli_query($con,$query);
$user=mysqli_fetch_array($do);
$String=$result['titel'];
$text_length = 30; // طول الحروف المراد ظهورها
if (strlen($String) > $text_length) {
// اذا كان طول النص اكبر من النص المراد ظهورة نفذ التالي
$String = substr($String, 0, 33);
// قص من النص التالي ما بعد الرقم في المتغير الخاص بطول الحروف المراد ظهورها
$String .= " ...";
// اضف إلى النص بعد ارجاعه هذه النقاط
}
?>
<div class="col-md-3" >
<div class="panel panel-default ">
<!-- Default panel contents -->
<div class="panel-heading" >
<?php
echo $String;
?>
</div>
<div class="panel-body">
<p><span class="glyphicon glyphicon-user"></span><b> <?php echo $user['username']; ?></b> </p>
<p> <span class="glyphicon glyphicon-folder-open"></span><b> <?php echo $lang['name']; ?></b></p>
</div>
<a href="show<?php echo $result['id']; ?>"><div class="panel-footer text-center ">
<b>عرض التحدي</b>
</div></a>
</div>
</div>
<?php } ?>
</div>
Hi this is the code it's only showing the first result in while loop I want 8 results.
I have 3 tables from MySQL and 3 querys I tried every thing I could but nothing changed.
Any help?
It's PHP 5.4 and mysqli class
Update: now the code works
<div class="row">
<?php
require 'config.php';
$query = "SELECT * FROM `posts` ORDER BY `id` DESC LIMIT 8";
$do = mysqli_query($con, $query) ;
while ($result = mysqli_fetch_assoc($do)){
$query="SELECT * FROM `lang` where id='$result[langid]'";
$do1=mysqli_query($con,$query);
$query="SELECT * FROM `users` where id='$result[userid]'";
$do2=mysqli_query($con,$query);
$String=$result['titel'];
$text_length = 30; // طول الحروف المراد ظهورها
if (strlen($String) > $text_length) {
// اذا كان طول النص اكبر من النص المراد ظهورة نفذ التالي
$String = substr($String, 0, 33);
// قص من النص التالي ما بعد الرقم في المتغير الخاص بطول الحروف المراد ظهورها
$String .= " ...";
// اضف إلى النص بعد ارجاعه هذه النقاط
}
?>
<div class="col-md-3" >
<div class="panel panel-default ">
<!-- Default panel contents -->
<div class="panel-heading" >
<?php
while ( $user=mysqli_fetch_assoc($do2) AND $lang=mysqli_fetch_assoc($do1) ){
echo $String;
?>
</div>
<div class="panel-body">
<p><span class="glyphicon glyphicon-user"></span><b> <?php echo $user['username']; ?></b> </p>
<p> <span class="glyphicon glyphicon-folder-open"></span><b> <?php echo $lang['name']; ?></b></p>
</div>
<a href="show<?php echo $result['id']; ?>"><div class="panel-footer text-center ">
<b>عرض التحدي</b>
</div></a>
</div>
</div>
<?php }} ?>
</div>
You are doing several queries, but looping only on the last one which is SELECT * FROM 'users' where id='$result[userid]', and it sounds like this query is going to give you a single result. (A single user)
You can either store the results of each queries, and use them all in a single loop later on, or join your tables to get all the data you want from a single query.