i want to dynamically display content in 3 bootstrap colums.
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<content>
</div> <---- Problem (should be placed at the very end of the column,
but the same code should also fill 2nd and 3rd columns)
while i fetch the query to mysql. Also i want object to sort in descending order from left to right (id = 51, id = 50, id = 42 (last digit in the object title is id))
I was able to do that, using row_number and row_number%3=0 row_number%3=1 and row_number%3=2 to display 3 columns, but i have to make 3 queries to the database along with 3 blocks of html(which is bad).
SELECT *
FROM (
SELECT
#row_number:=#row_number + 1 AS rownum, id,title, description, ...etc
FROM (
SELECT #row_number:=0) r, flats ORDER BY id DESC) ranked WHERE rownum%3=1 ORDER BY id DESC
But, when i started to implement filters, it caused problems with displaying objects, because not every column had the object i wanted to display, but i had own query for every column.
Problems with filters
What i want: Dynamically form 3 separate columns with content to use one MYSQL query.
Waiting for your help!
Example of 1 of 3 columns:
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<?php
$zapros = $DB_con->prepare('SELECT *
FROM (
SELECT
#row_number:=#row_number + 1 AS rownum, id,title, description,type, area,address, square, name, phone, email, price, avito, farpost
FROM (
SELECT #row_number:=0) r, flats ORDER BY id DESC) ranked WHERE rownum%3=1 ORDER BY id DESC');
$zapros->execute();
$rowsone=$zapros->rowCount();
if($zapros->rowCount() > 0)
{$tmpCount = 1;
$count=$zapros->rowCount();
while($data=$zapros->fetch(PDO::FETCH_ASSOC))
{
extract($data);
$number=$data['id'];
$imagestm=$DB_con->prepare('SELECT file FROM flats_images WHERE post_id=:uid LIMIT 1');
$imagestm->bindParam(':uid',$number);
$imagestm->execute();
$imgrow=$imagestm->fetch(PDO::FETCH_ASSOC);
extract($imgrow);?>
<div class="well-lg well-smallborders">
<a href="flat.php?flat_id=<?php echo $data['id']; ?>">
<img src="/mysql/uploads/<?php echo $imgrow['file']; ?>" class="img-responsive title-image center-block" /></a>
<div class="flat-price center-block"><?php echo $data['price']; ?><span class="glyphicon glyphicon-rub" aria-hidden="true"></span> </div>
<div class="flat-title"><?php echo $data['title'];?> <?php echo $data['id']; ?></div>
<div class="dimmed-text left"><?php echo $data['type']; ?> </div>
<div class="dimmed-text right"><div class="tooltip_my"><span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span><?php echo $data['area'];?> <span class="tooltiptext"><?php echo $data['address']; ?></span></div></div>
<br>
<div class="dimmed-text left"><div class="tooltip_my"> <span class="glyphicon glyphicon-phone" aria-hidden="true"></span><?php echo $data['phone'];?><span class="tooltiptext"><?php echo $data['name'];?></span></div></div>
<div class="dimmed-text right"> <?php echo $data['square'];?></div>
<table class="flats-table">
<tr>
<td colspan="3">
<button id="collapsar" class="btn btn-info pull-left" data-toggle="collapse" data-target="#hide-me<?php echo $tmpCount;?>"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="btntext">Показать миниатюры</span></button>
</span> <span class="btntext">Подробнее ...</span>
</td>
</tr>
<tr>
<td colspan="3">
<div id="hide-me<?php echo $tmpCount;?>" class="collapse">
<?
$imagestm2=$DB_con->prepare('SELECT file FROM flats_images WHERE post_id=:uid');
$imagestm2->bindParam(':uid',$number);
$imagestm2->execute();
for ($i = 1; $i <= $imagestm2->rowCount(); $i++) {
$imgrow2=$imagestm2->fetch(PDO::FETCH_ASSOC);
extract($imgrow2); ?>
<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4">
<div class="thumbnail"> <img src="mysql\uploads\<?php echo $imgrow2['file']; ?>" data-toggle="modal" data-target="#myModal" class="img-responsive"/></div>
</div>
<?
} ?>
</div>
</td>
</tr>
</table>
</div><?
$tmpCount++;
}}
?>
</div>
Actual result i want: Actual result
I think you are simply trying to iterate over your results, generate 3 columns of output, and then also apply filters, maybe through Javascript, which hide some of your elements. The simplest way I know to do that is as follows:
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
...
<!-- Bootstrap can manage with only 1 .row -->
</div>
I don't think it's possible to do, what i wanted to do, instead i found much easier way to display content: just unite 3 columns in one and put all data there. Ye, it has problems when you open the spoiler, but i think i'll deal with it. Thank you for all your answers.
Related
When printing data using a foreach, only the information of the first data in the table is printed and I have around 4 in it, I attach a capture first of what the foreach shows and I need each data to be printed correctly with your information, figure, indicator, etc.
Data that the foreach prints
https://i.stack.imgur.com/pVypz.png
Then the Foreach code
This error appears in several windows or screens that I have to print, but I emphasize this one because it is the one I am currently working on and trying to print it correctly.
Please, if information is missing, or I must include the controller, and model, confirm it for me, I will gladly do so, in the same way, I would like to advance that as a test the model consults directly with the client's ID and brings all the data corresponding to it.
Thanks in advance for your support.
foreach (array($datos2, $dataprograma) as $key => $datosProyecto) :
// echo $dataprograma[$key]['p_indicador'];
/*foreach ($datos2 as $value) :
foreach ($dataprograma as $v)*/
?>
<div class="row " style="width:96%!important;margin-left:0.7rem!important;">
<div class="col-md-2 border">
<br>
<div class=" text-center d-flex mx-auto border bg-info text-white"><br<br>
<a href="<?php echo base_url('proyecto_detalle') ?>" class="text-center text-white" align="center">
<?php echo $datos2[0]['titulo_p'] ?></a>
</div>
</div>
<div class=" col-md-3 p-3 border"> <br>
<h6 align="center" style="font-size:12px;">INDICADOR</h6>
<?php echo $dataprograma[0]['p_indicador'];?>
</textarea>
</div>
<div class="col-md-2 p-3 border"> <br>
<h6 align="center" style="font-size:12px;">METAS</h6>
<?php echo $datos2[0]['metas'] ?>
</div>
<div class="col-md-2 p-3 border"><br>
<h6 align="center" style="font-size:12px;">INSTITUCIÓN</h6>
<?php echo $datos2[0]['promotor_p'] ?>
</div>
<div class="col-md-3 p-3 border">
<div class="row">
<div class="col-md-6 ">
<h6 style="font-size:12px;">Población afectada</h6>
<?php echo $dataprograma[0]['p_afectada'] ?>
</div>
<div class="col-md-6">
<h6 style="font-size:11px;">Comunicación (%)</h6>
<input type="text" name="mejora_comunicacion" class="form-control form_p" placeholder="%" required id="mjr" cols="16" rows="4"></input>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
I am trying to create categories nav-pill with bootstrap 5.
İt has two cols first one is futured post and second one displays 5 posts.
I have tried like this but it wasn't right because they are in different columns (side by side), simple example:
$sql = "SELECT * FROM articles WHERE article_id = ? ORDER BY article_id DESC";
$result = $pdo->prepare($sql);
$result->execute([$cats['cat_id']]);
if ($result->rowCount() > 0) {
$array = array('class 1', 'class 2');
$i=0;
while($row = $result->fetch()) { ?>
<div class="<?php $array[$i];?>">
</div>
<?php
$i++;
}
}
?>
My html:
<div class="row">
<!-- first futured column ->
<div class="col-sm-6">
<div class="whats-news-single mb-40 mb-40">
<div class="whates-img">
<img src="..." alt="">
</div>
<div class="whates-caption">
Secretart for Economic Air plane that looks like
<p>Struggling to sell one the market won’t stop actress and the and singer Jennifer Lopez.</p>
<span class="small">by Alice cloe - Jun 19, 2020</span>
</div>
</div>
</div>
<!-- second column displays 5 articles ->
<div class="col-sm-6">
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>The pros and cons of business agency</h6>
<div class="small mt-1">May 17, 2021</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>5 reasons why you shouldn't startup</h6>
<div class="small mt-1">Apr 04, 2021</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>Ten questions you should answer truthfully.</h6>
<div class="small mt-1">Jun 30, 2021</div>
</div>
</div>
</div>
<div class="card mb-3">
<div class="row g-3">
<div class="col-4">
<img class="rounded" src="..." alt="">
</div>
<div class="col-8">
<h6>Five unbelievable facts about money.</h6>
<div class="small mt-1">Nov 29, 2021</div>
</div>
</div>
</div>
</div>
</div>
This is how it has to look like
enter image description here
I'm a bit confused by your question. Is the featured Post a randomly selected post, or is it always the newest in the database? If its always the newest, you could just query by article_id desc (as you're currently doing) and then access the first post via:
$array[0]
That way you can now create your featured post view by using all the data available in the first index of your array.This only works if you put your query results into an array, as described here:. Note that you should use mysqli functions, and not mysql. For the next five, you can then make use of for to display five more articles:
for($i = 1; $i <= 5;$i++) {
// repeat the section for one post five times
}
This will allow you to create the view you described.
I need to display cards horizontally from my database using PHP
My code is below
function getHighlights($conn){0
$q = "SELECT *, MONTHNAME(date) AS themonth, DAYOFMONTH(date) AS theday, YEAR(date) AS theyear FROM highlights ORDER BY date DESC LIMIT 0,3";
$r = mysqli_query($conn, $q);
while($page = mysqli_fetch_assoc($r)){
echo '
<div class="container">
<div class="row-fluid">
<div class="card-deck mt-5 mb-4">
<div class="card col-md-6 col-lg-4 col-xs-12">
<img src="../thadd/images/'.$page['image'].'" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">'.$page['title'].'</h5>
<p class="card-text mb-5">'.$page['message'].'</p>
<div class="text-center mb-3">
Read More →
</div>
<div class="card-footer text-muted">
Posted on Tuesday by '.$page['author'].'
</div>
</div>
</div>
</div>
</div>
</div>
';
}
Generally, move the row out of the loop as shown in the following pseudo code.
<div class="container">
<div class="row">
-- WHILE LOOP --
<div class="col">
-- OUTPUT DATA --
</div> <!-- col -->
-- END WHILE --
</div><!-- row -->
</div> <!-- container -->
Read the bootstrap grid
https://getbootstrap.com/docs/4.3/layout/grid/
Im trying to add a group onto some bootstrap cards so that a the cards are displaying the data first and then the relevant cards after, e.g:
22 March 2018
1st-Card 2nd-Card
23 March 2018
1st-Card
At the moment I have this, but this displays all of my cards on a row:
<div class="card">
<div class="card-body">
<div class="card-header"><i class="material-icons floatleft">today</i><div floatleft>'.date("d/m/Y", strtotime($row['Date'])).'</div></div>
<h5 class="card-title">'.$row['Firstname'].' '.$row['Surname'].'</h5>
<p class="card-text">'.$row['Notes'].'</p>
</div>
<div class="card-footer">
<small class="text-muted">Added: '.date("d/m/Y", strtotime($row['timestamp'])).'</small>
</div>
</div>
</div>
Is their anyway to group by date?
This is my PHP for each row:
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($tablequery))
{
$amount = $row['LineRef'] == 0 ? '' :
number_format($row['LineRef']);
echo
' <div class="col-sm-3 OMHCardPadding">
<div class="card">
<div class="card-body">
<div class="card-header"><i class="material-icons floatleft">today</i>
<div floatleft>'.date("d/m/Y", strtotime($row['Date'])).'</div></div>
<h5 class="card-title OMHCardPadding">'.$row['Firstname'].' '.$row['Surname'].'</h5>
<p class="card-text OMHCardPadding">'.$row['Notes'].'</p> </div> <div class="card-footer">
<small class="text-muted">Added: '.date("d/m/Y",strtotime($row['timestamp'])).'</small>
</div>
</div>
</div>
';
$total += $row['LineRef'];
$no++;
}?>
My actual query is just a simple SELECT statement:
SELECT * FROM APPOINTMENTS
I have this carousel that I want to make dynamic. To operate, the carousel must begin with a class
<div class="item active">
and must stay out of the while loop. After the fourth record extract, the class must become simply
<div class="item">
In summary:
0 to 4 -> <div class="item active">
5 to 8 --><div class="item">
9 to 12 --> <div class="item"> ....so on
How do I count the records extracted?
Thanks
<?php
$banner = "SELECT * FROM tbl_banner";
$result_b = dbQuery($banner);
// here --> <div class="item active"> or <div class="item">
while($row_b = dbFetchAssoc($result_b)) {
extract($row_b);
?>
<div class="col-md-3">
<div class="w-box inverse">
<div class="figure">
<img alt="" src="banner/<?php echo $img; ?>" class="img-responsive">
<div class="figcaption bg-2"></div>
<div class="figcaption-btn">
<i class="fa fa-plus-circle"></i> Zoom
<i class="fa fa-link"></i> View
</div>
</div>
<div class="row">
<div class="col-xs-9">
<h2><?php echo $img_title; ?></h2>
<small><?php echo $img_desc; ?></small>
</div>
</div>
</div>
</div>
<?php
}
?>
You can use num_rows to see how many rows were returned. Unfortunately from your question I can't tell whether you're using MySQL, MySQLi or PDO as it seems you pass all your queries into a class.
For MySQLi use the following:
$num = $result_b->num_rows;
SELECT COUNT(*) AS cnt FROM tbl_banner
OR
count( $res ); # in php
Also see: Which is fastest? SELECT SQL_CALC_FOUND_ROWS FROM `table`, or SELECT COUNT(*)
I don't understand....
I would like a result like this, explained in this way:
$query ="SELECT .....
<div class="row">
<div class="item active">
while {
<div1>...</div>
<div2>...</div>
<div3>...</div>
<div4>...</div>
} //end while
</div>
</div>
<div class="row">
<div class="item">
while {
<div4>...</div>
<div6>...</div>
<div7>...</div>
<div8>...</div>
} //end while
etc etc