Why data will post on the same "window" - php

I am trying to want to post data on many "windows", not just one.
To help explain what I am doing, here are some examples.
Screenshot 1
Next, I want to post news on many windows like this:
Screenshot 2
HTML:
<div id="news">
<div id="newsWindow">
<div id="newsTitle">
<?php
session_start();
$uchwyt=mysql_connect('=====','=====','=====')
or die('Nieudane polaczenie z baza danych...');
mysql_select_db('a6039035_news')
or die('Nie udalo sie wybrac bazy danych...');
$link=mysql_query("SELECT * FROM news ORDER BY id desc LIMIT 4");
while($wiersz=mysql_fetch_array($link))
{
echo $wiersz['tytul'];
echo "<br>\n";
}
mysql_close($uchwyt);
?>
</div>
<div id="newsInfo">
<div class="time">
<?php
session_start();
$uchwyt=mysql_connect('=====','=====','=====')
or die('Nieudane polaczenie z baza danych...');
mysql_select_db('a6039035_news')
or die('Nie udalo sie wybrac bazy danych...');
$link=mysql_query("SELECT * FROM news ORDER BY id desc LIMIT 4");
while($wiersz=mysql_fetch_array($link))
{
echo $wiersz['godzina'];
}
mysql_close($uchwyt);
?>
</div>
<div class="date">
<?php
session_start();
$uchwyt=mysql_connect('=====','=====','=====')
or die('Nieudane polaczenie z baza danych...');
mysql_select_db('a6039035_news')
or die('Nie udalo sie wybrac bazy danych...');
$link=mysql_query("SELECT * FROM news ORDER BY id desc LIMIT 4");
while($wiersz=mysql_fetch_array($link))
{
echo $wiersz['data'];
}
mysql_close($uchwyt);
?>
</div>
</div>
<div id="newsContent">
<p>
<?php
session_start();
$uchwyt=mysql_connect('=====','=====','====')
or die('Nieudane polaczenie z baza danych...');
mysql_select_db('a6039035_news')
or die('Nie udalo sie wybrac bazy danych...');
$link=mysql_query("SELECT * FROM news ORDER BY id desc LIMIT 4");
while($wiersz=mysql_fetch_array($link))
{
echo $wiersz['tresc'];
}
mysql_close($uchwyt);
?>
</p>
<div id="newsMore">
Czytaj więcej...
</div>
</div>

You are doing a query and loop in each news <div>. You need to do the query before, and then loop over each news <div> and returned data
<?php
$uchwyt=mysql_connect('=====','=====','=====')
or die('Nieudane polaczenie z baza danych...');
mysql_select_db('a6039035_news')
or die('Nie udalo sie wybrac bazy danych...');
$link=mysql_query("SELECT * FROM news ORDER BY id desc LIMIT 4");
?>
<div id="news">
<?php
while($wiersz=mysql_fetch_array($link))
{
?>
<div class="newsWindow">
<div class="newsTitle">
<?php
echo $wiersz['tytul'];
echo "<br>\n";
?>
</div>
<div class="newsInfo">
<div class="time">
<?php
echo $wiersz['godzina'];
?>
</div>
<div class="date">
<?php
echo $wiersz['data'];
?>
</div>
</div>
<div id="newsContent">
<p>
<?php
echo $wiersz['tresc'];
?>
</p>
<div id="newsMore">
Czytaj więcej...
</div>
</div>
<?php
}
?>

Related

Weekly Menu Rotation

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";
}

DIV Card misplacing in another row

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;
}

Mysqli query are not fetching database values

I am trying with php 7.0 as everyone recommend me here to start with it as 5.6 has been depreveted . But after writing its code i am unable to fetch the values from database. what wrong i am doing here. thank you
//This is my aboutus page//
<div class="col-lg-10">
<?php include('config.php');
$query = mysqli_query('select * from about ');
while($row = mysqli_fetch_array($query)){
?>
<h5>
<?php echo $row['about_desc'] ;?>
<br>
<br>
<?php echo $row['about_desc1']; ?>
<br>
<br>
<?php echo $row['about_desc2'] ;?>
<br>
<br>
<?php echo $row['about_desc3'] ;?>
<br>
<br>
<?php echo $row['about_desc4']; ?>
</h5>
<hr class="featurrate-divider">
<?php
}
?>
</div>
</div>
<div id="tab-1">
<?php include('config.php ');
$query = mysqli_query('select * from news LIMIT 0,2');
while($row = mysqli_fetch_array($query)){
?>
<div class="news">
<h4><u><?php echo $row['news_name']; ?></u></h4>
<h5><font color="black"><?php echo $row['dat']; ?></font></h5>
<p><?php echo $row['news_desc']; ?></p>
se mer >>
</div>
<hr class="featurrate-divider">
<?php
}
?>
</div>
//This is my config.php file//
<?php
$connection = mysqli_connect('localhost','root','','dandelion') or die(mysqli_error($connection));
?>
Looking for good suggestion as a learner. thank you
Your About us page should be like this:
<body>
<div class="col-lg-10">
<?php include('config.php');
$query = mysqli_query($connection, 'select * from about ');
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
?>
<h5>
<?php echo $row['about_desc'] ;?>
<br>
<br>
<?php echo $row['about_desc1']; ?>
<br>
<br>
<?php echo $row['about_desc2'] ;?>
<br>
<br>
<?php echo $row['about_desc3'] ;?>
<br>
<br>
<?php echo $row['about_desc4']; ?>
</h5>
<hr class="featurrate-divider">
<?php
}
?>
</div>
</div>
<div id="tab-1">
<?php include('config.php ');
$query = mysqli_query($connection, 'select * from news LIMIT 0,2');
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
?>
<div class="news">
<h4><u><?php echo $row['news_name']; ?></u></h4>
<h5><font color="black"><?php echo $row['dat']; ?></font></h5>
<p><?php echo $row['news_desc']; ?></p>
se mer >>
</div>
<hr class="featurrate-divider">
<?php
}
?>
</div>
</body>
if your database connection is sucessfully work and problem with fetching data than use number.it may be useful to fetch the data.
<?php echo $row[o]; ?>
<?php echo $row[1]; ?>
instead of
<?php echo $row['about_desc1']; ?>

Filter SQL data via select option menu HTML - PHP

I'm trying to create a filter option on a select option menu, but I can't seem to make it work.
The goal of my filter is to filter the data on "stad".
Table (Huis):
id = int(2) primary key Auto_increment
stad = varchar(25)
stad means city in the Dutch Language
-------------------------
| id | .....| stad |
| 1 |......| Amsterdam |
| 2 |......| London |
-------------------------
Where ..... is other columns.
I'm looping the option menu with a while loop, so it automatically adds a new option when there's a new "stad" registered.
Do I have to use a button in order to receive the selected option and filter the displayed data?
My php file:
<form action="" method="post" name="filter">
<select class="filtermenu">
<option selected="true" disabled="disabled">Plaatsnaam</option>
<?php while($overzichtHuis = mysqli_fetch_assoc($overzichtRes)): ?>
<option value="<?php echo $overzichtHuis['stad']?>"><?php echo $overzichtHuis['stad']?></option>
<?php endwhile; ?>
</select>
<input type="submit" value="Filter toepassen" onclick="insert()">
</form>
//SQL Query
$overzichtData = "SELECT * FROM huis";
$overzichtRes = mysqli_query($con, $overzichtData) or die(mysqli_error($con));
$detailsData = "SELECT * FROM huis ORDER BY id DESC";
$detailsRes = mysqli_query($con, $detailsData) or die(mysqli_error($con));
//Displayed data
<?php while($detailsHuis = mysqli_fetch_assoc($detailsRes)): ?>
<div class="item overzicht-item">
<figure class="overzichtfoto">
<img src="<?php echo $detailsHuis['afbeelding']?>" alt="" class="img-responsive">
<?php if($detailsHuis['type'] == "Te koop"):?>
<span class="label koop"><?php echo $detailsHuis['type']?></span>
<?php elseif($detailsHuis['type'] == "Te huur"):?>
<span class="label huur"><?php echo $detailsHuis['type']?></span>
<?php endif;?>
<div class="overlay-overzicht"></div>
</figure>
<div class="overzicht-details">
<div class="item-header clearfix">
<h3 class="overzicht-titel">Huis in <?php echo $detailsHuis['stad']?></h3>
<span class="favorite"><i class="fa fa-heart" style="margin-right: 0px;"></i></span>
<span class="overzicht-plaats"><i class="fa fa-map-marker"></i><b><?php echo $detailsHuis['stad']?></b> <?php echo $detailsHuis['provincie']?></span>
</div>
<div class="item-detail overzicht-detail">
<span class="price price-overzicht">€ <?php echo $detailsHuis['prijs']?></span>
<div class="left">
<span class="bed"><?php echo $detailsHuis['kamers']?></span>
<span class="bath"><?php echo $detailsHuis['badkamers']?></span>
<span class="garage"><?php echo $detailsHuis['garage']?></span>
</div>
<div class="right">
<span class="area"><?php echo $detailsHuis['oppervlakte']?> m2</span>
</div>
</div>
</div>
</div>
<?php endwhile; ?>
//Me trying to create a PHP Function
function insert(){
if(isset($_RETURN['value'])){
if($_RETURN['filtermenu'] == 'Amsterdam')
{
$query = "SELECT * FROM huis WHERE stad='Amsterdam'";
}
elseif($_RETURN['filtermenu'] == 'London')
{
$query = "SELECT * FROM huis WHERE stad='London'";
}
else
{
$query = "SELECT * FROM huis";
}
$sql = mysql_query($overzichtRes);
}
}
You may attach onchange attr to select tag itself. You don't even need form tag if you working with this event by javascript (as I could see from your code)

Bootstrap Data-toggle not working on PHP using a "while "

I have a problem whith my " Bootstrap Collapse" . My query display only the fist $ID_Producto of all my rows.
<?php
$Consulta_Productos = $Conexion ->query( "SELECT * FROM productos ORDER BY Producto_Categoria");
while($Fila_Productos = $Consulta_Productos->fetch_assoc())
{
$ID_Producto = $Fila_Productos['ID_Producto'];
?>
<span data-toggle="collapse" data-target="#demo">Show ID <?php echo $ID_Producto ?></span>
<div id="demo" class="collapse">
<?php echo $ID_Producto; ?>
</div>
<br>
<?php
}
?>
your data-target="#demo" and id="demo" are the same for all the products.
try this
<?php
$Consulta_Productos = $Conexion ->query( "SELECT * FROM productos ORDER BY Producto_Categoria");
while($Fila_Productos = $Consulta_Productos->fetch_assoc())
{
$ID_Producto = $Fila_Productos['ID_Producto'];
?>
<span data-toggle="collapse" data-target="#demo<?php echo $ID_Producto; ?>">Show ID <?php echo $ID_Producto ?></span>
<div id="demo<?php echo $ID_Producto; ?>" class="collapse">
<?php echo $ID_Producto; ?>
</div>
<br>
<?php
}
?>

Categories