I'm using a while loop to echo a PHP array :
$connect = mysqli_connect("localhost", "user", "password", "db");
$sql = "SELECT * FROM table ORDER BY RAND() LIMIT 0,4";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 0)
{
echo'<section>
<div class="container">
<div class="row">
<h2 class="bold">title</h2>
<hr> ';
while($row = mysqli_fetch_array($result))
{
echo'
<div class="col-sm-3 col-md-3 col-md-push-3">
<div class="portfolio-wrapper">
<div class="portfolio-single">
<div class="portfolio-thumb">
<img src="'.$row['image'].'" class="img-responsive" alt="'.$row['alt'].">
</div>
</div>
<div class="portfolio-info" dir="rtl">
<a href="'.$row['link2']." target="_self"><h2> </h2>
<h6>'.$row['title'].</h6>
</a>
</div>
</div>
</div>';
}
echo'
</div>
</div>
</section';
}
?>
This code works fine for me but the problem is that i need to echo 4 different
for example :
first will be: <div class="col-sm-3 col-md-3 col-md-push-9">
second: <div class="col-sm-3 col-md-3 col-md-push-3">
third: <div class="col-sm-3 col-md-3 col-md-pull-3">
last: <div class="col-sm-3 col-md-3 col-md-pull-9">
any ideas how can i accomplish this structure using a while loop ?
Use a counter, and put your classes into an array like this:
$classes = [
"col-sm-3 col-md-3 col-md-push-9",
"col-sm-3 col-md-3 col-md-push-3",
"col-sm-3 col-md-3 col-md-pull-3",
"col-sm-3 col-md-3 col-md-pull-9"
];
$i = 0;
while($row = mysqli_fetch_array($result)) {
if ($i > 3) {
$i = 0;
}
?>
<div class="<?php echo $classes[$i]; ?>">
Your content comes here
</div>
<?php
$i++;
}
NOTE
This is resets the counter, if there is no index like that in the array. Your script assumes, that you will get always 4 rows.
<?php
$connect = mysqli_connect("localhost", "user", "password", "db");
$sql = "SELECT * FROM table ORDER BY RAND() LIMIT 0,4";
$result = mysqli_query($connect, $sql);
$i = 1;
$count = count($result);
if(mysqli_num_rows($result) > 0)
{
echo'<section>
<div class="container">
<div class="row">
<h2 class="bold">title</h2>
<hr> ';
while($row = mysqli_fetch_array($result))
{
if($i==1){echo '<div class="col-sm-3 col-md-3 col-md-push-9">';}
elseif($i == $count){echo '<div class="col-sm-3 col-md-3 col-md-pull-9">';}
elseif($i%2 == 0){echo '<div class="col-sm-3 col-md-3 col-md-push-3">';}
elseif($i%3 == 0){echo '<div class="col-sm-3 col-md-3 col-md-pull-9">';}
echo'
<div class="portfolio-wrapper">
<div class="portfolio-single">
<div class="portfolio-thumb">
<img src="'.$row['image'].'" class="img-responsive" alt="'.$row['alt'].">
</div>
</div>
<div class="portfolio-info" dir="rtl">
<a href="'.$row['link2']." target="_self"><h2> </h2>
<h6>'.$row['title'].</h6>
</a>
</div>
</div>
</div>';
$i =$i+1;
}
echo'
</div>
</div>
</section';
}
?>
Related
I'm fetching data from mysql table with mysqli fetch array and after the while of fetching i want to the carousel item showing what his index number from the array so i can identify them using the index number for giving active property
<?php
$qry = mysqli_query($koneksi, "SELECT * FROM t_berita ORDER BY tanggal DESC LIMIT 3");
while($row = mysqli_fetch_array($qry, MYSQLI_ASSOC)){
$qrygbr = mysqli_query($koneksi, "SELECT * FROM t_gambar WHERE id_berita = '".$row['id']."'");;
$rowcount=mysqli_num_rows($qry);
while ($rowgbr = mysqli_fetch_array($qrygbr, MYSQLI_ASSOC)) {
# code...
?>
<div class="carousel-item active">
<div class="card">
<div class="card-body" style="padding: 0;">
<div class="row">
<div class="col-lg-6"><img class="img-fluid" style="width: 100%;height: 100%;background-image: url(data:image/jpeg;base64,<?php echo base64_encode($rowgbr['gambar']);?>);background-position: center;background-size: cover;background-repeat: no-repeat;" /></div>
<div class="col-lg-6">
<div class="d-md-flex d-lg-flex flex-column justify-content-md-center align-items-md-center justify-content-lg-center align-items-lg-start" style="padding-top: 20px;padding-left: 10px;padding-right: 10px;height: 100%;margin-bottom: 20px;">
<h4><?php
echo $row['judul'];
?></h4>
<h6 class="text-muted card-subtitle mb-2">
<?php
echo $row['tanggal'].$rowgbr[];
?>
</h6>
<p>
<?php
echo $row['artikel'];
?>
</p>
<p>
</p>
<div class="d-flex"></div><a class="btn btn-primary" role="button" href="bacaberita.php?id=<?php echo $row['id'] ?>">Read More</a></div>
</div>
</div>
</div>
</div>
</div>
<?php
}
}
mysqli_close($koneksi);
?>
change the 2nd query
$qrygbr = mysqli_query($koneksi, "SELECT #a:=#a+1 serial_number,t_gambar.* FROM t_gambar, (SELECT #a:= 0) AS a WHERE t_gambar.id_berita = '".$row['id']."'");
while ($rowgbr = mysqli_fetch_array($qrygbr, MYSQLI_ASSOC)) {
echo $rowgbr['serial_number']; //this is you your needed serial number
}
The following should help you understand what you need to do. I've applied a $count variable within the loop to increase as the loop continues. I've added the variable to a to show you how it works.
<?php
$koneksi = mysqli_connect('localhost', 'admbumm_DedSec', 'omnimon786.,', 'admbumm_selipin');
$qry = mysqli_query($koneksi, "SELECT * FROM t_berita ORDER BY tanggal DESC LIMIT 3");
while($row = mysqli_fetch_array($qry, MYSQLI_ASSOC)){
$qrygbr = mysqli_query($koneksi, "SELECT * FROM t_gambar WHERE id_berita = '".$row['id']."'");
$rowcount=mysqli_num_rows($qry);
$count = 1;
while ($rowgbr = mysqli_fetch_array($qrygbr, MYSQLI_ASSOC)) {
# code...
?>
<div class="carousel-item active">
<div class="card">
<div class="card-body" style="padding: 0;">
<div class="row">
<div class="col-lg-6"><img class="img-fluid" style="width: 100%;height: 100%;background-image: url(data:image/jpeg;base64,<?php echo base64_encode($rowgbr['gambar']);?>);background-position: center;background-size: cover;background-repeat: no-repeat;" /></div>
<div class="col-lg-6">
<div class="d-md-flex d-lg-flex flex-column justify-content-md-center align-items-md-center justify-content-lg-center align-items-lg-start" style="padding-top: 20px;padding-left: 10px;padding-right: 10px;height: 100%;margin-bottom: 20px;">
<h4><?php
echo $row['judul'];
?></h4>
<h6 class="text-muted card-subtitle mb-2">
<?php
echo $row['tanggal'].$rowgbr[];
?>
</h6>
<p>
<?php
echo $row['artikel'];
?>
</p>
<p>
<p>
<?php
echo $count;
?>
</p>
</p>
<div class="d-flex"></div><a class="btn btn-primary" role="button" href="bacaberita.php?id=<?php echo $row['id'] ?>">Read More</a></div>
</div>
</div>
</div>
</div>
</div>
<?php
$count = $count + 1;
}
}
mysqli_close($koneksi);
?>
you might want to add another variable inside your SQL Query like so
$qry = mysqli_query($koneksi, "SELECT * FROM t_berita ORDER BY tanggal DESC LIMIT 3");
to
$qry = mysqli_query($koneksi, "SELECT COUNT(*) as c,* FROM t_berita ORDER BY tanggal DESC LIMIT 3");
basically, SQL will count the total rows available and put it c. So you can just do some simple loop with c inside your PHP code
I am working on a project in which there is a main lead table with rows and column values as in MYSQL table. I want to add some value based filter using drop-down to applied over the table so that view of large number of rows in table can be minimized.
But i am confused to how to generate the table each time when i apply filter.
Please guide me and comment if any code part is needed. Its screenshot is attached.
Below is a part of my code as screenshot attached above and is inside HTML body.
Dashboard.html
<!-- View Main Lead Table with Filters -->
<section class="operation" id="view_lead_info" style="display: none;">
<!-- Filters -->
<div class="row">
<div class="col">
<label><p><b>Select Filter</b></p></label>
</div>
</div>
<div class="row">
<div class="col span-1-of-4">
<div class="row">
<div class="col span-1-of-4">
Lead Status:
</div>
<div class="col span-2-of-4">
<select><option>Select</option>
<?php
echo "<option value='Active'>Active Leads</option>";
echo "<option value='Paused'>Paused Leads</option>";
echo "<option value='Expired'>Expired Leads</option>";
echo "<option value='Unsubscribed'>Unsubscribed</option>";
?>
</select>
</div>
</div>
</div>
<div class="col span-1-of-3">
<div class="row">
<div class="col span-1-of-4">
Campaign Status:
</div>
<div class="col span-2-of-4">
<select><option>Select</option>
<?php
echo "<option value='Active'>Active</option>";
echo "<option value='Paused'>Paused</option>";
echo "<option value='Expired'>Expired</option>";
echo "<option value='Unsubscribed'>Unsubscribed</option>";
?>
</select>
</div>
</div>
</div>
<div class="col span-1-of-3">
<div class="row">
<div class="col span-1-of-3">
Company Name:
</div>
<div class="col span-2-of-3">
<?php
include('./server/connection.php');
$sqlSelect="SELECT * FROM tbl_main_lead_info ORDER By Company ASC";
$result = $conn -> query ($sqlSelect);
echo "<select>";
echo "<option>select</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='$row[Company]'> $row[Company] </option>";
}
echo "</select>";
?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col span-1-of-4">
<div class="row">
<div class="col span-1-of-4">
State:
</div>
<div class="col span-2-of-4">
<?php
include('./server/connection.php');
$sqlSelect="SELECT * FROM tbl_state_info ORDER By StateName ASC";
$result = $conn -> query ($sqlSelect);
$result = $conn -> query ($sqlSelect);
echo "<select name='StateName'>";
echo "<option>select</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='$row[StateName]'> $row[StateName] </option>";
}
echo "</select>";
?>
</div>
</div>
</div>
<div class="col span-1-of-3">
<div class="row">
<div class="col span-1-of-4">
Country:
</div>
<div class="col span-2-of-4">
<?php
include('./server/connection.php');
$sqlSelect="SELECT * FROM tbl_country_info ORDER By CountryName ASC";
$result = $conn -> query ($sqlSelect);
$result = $conn -> query ($sqlSelect);
echo "<select name='CountryName'>";
echo "<option>select</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='$row[CountryName]'> $row[CountryName] </option>";
}
echo "</select>";
?>
</div>
</div>
</div>
<div class="col span-1-of-3">
<div class="row">
<div class="col span-1-of-3">
Firm Type:
</div>
<div class="col span-2-of-3">
<?php
include('./server/connection.php');
$sqlSelect="SELECT * FROM tbl_firm_type_info ORDER By FirmType_Value ASC";
$result = $conn -> query ($sqlSelect);
$result = $conn -> query ($sqlSelect);
echo "<select name='FirmType'>";
echo "<option>select</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='$row[FirmType_Value]'> $row[FirmType_Value] </option>";
}
echo "</select>";
?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col span-1-of-4">
<div class="row">
<div class="col span-1-of-4">
Firm Size:
</div>
<div class="col span-2-of-4">
<?php
include('./server/connection.php');
$sqlSelect="SELECT * FROM tbl_firm_size_info ORDER By FirmSize_Id ASC";
$result = $conn -> query ($sqlSelect);
$result = $conn -> query ($sqlSelect);
echo "<select name='FirmSize'>";
echo "<option>select</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='$row[FirmSize_Value]'> $row[FirmSize_Value] </option>";
}
echo "</select>";
?>
</div>
</div>
</div>
<div class="col span-1-of-4">
<div class="row">
<div class="col span-1-of-3">
Tech Area:
</div>
<div class="col span-2-of-3">
<?php
include('./server/connection.php');
$sqlSelect="SELECT * FROM tbl_tech_area_info ORDER By TechAreaName ASC";
$result = $conn -> query ($sqlSelect);
$result = $conn -> query ($sqlSelect);
echo "<select name='TechAreaName'>";
echo "<option>select</option>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='$row[TechAreaName]'> $row[TechAreaName] </option>";
}
echo "</select>";
?>
</div>
</div>
</div>
<div class="col span-1-of-4">
<div class="row">
<div class="col span-1-of-4">
Start Date:
</div>
<div class="col span-3-of-4">
<?php
echo "<input type='date' name='startdate'>";
?>
</div>
</div>
</div>
<div class="col span-1-of-4">
<div class="row">
<div class="col span-1-of-4">
End Date:
</div>
<div class="col span-3-of-4">
<?php
echo "<input type='date' name='enddate'>";
?>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<div class="row">
<div class="col span-3-of-4">
</div>
</div>
</div>
<div class="col span-1-of-3">
<div class="row">
<div class="col span-3-of-4">
<div class="row">
<div class="col span-1-of-3">
<label></label>
</div>
<div class="col span-2-of-3">
<input type="submit" value="Search">
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Main Tables Campaign and Lead Table -->
<div class="row">
<!-- MAIN TABLE-->
<div class="col" >
<button class="viewMainTable" onclick="viewMainTable();" name="viewMainTable">Lead Table</button>
<button class="viewCampaignTable" onclick="viewCampaignTable();" name="viewCampaignTable">Campaign Table</button>
<div class="row">
<div class="col span-4-of-4">
<table class="display_table" id='main_lead_table' style="display: none;">
<th>Sr.No.</th>
<th>LeadID - Name</th>
<th>Company</th>
<th>Location</th>
<th>Communication</th>
<th>Last Contact Date</th>
<th>Next Contact Date</th>
<th>Lead Status</th>
<th>Details</th>
<?php
include('./server/connection.php');
$selectSQL = "SELECT * FROM `tbl_main_lead_info`";
$result = $conn -> query ($selectSQL);
$i = 1;
while ($row = mysqli_fetch_array($result)) {
printf( "<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>",
$i,
$row['Lead_Id']." - ".$row['FirstName']." ".$row['LastName'],
$row['Company'],
$row['State']."<br>".$row['Country'],
$row['Phone']."<br>".$row['Email'],
date('d-m-Y', strtotime($row['LastContactDate'])),
date('d-m-Y', strtotime($row['NextContactDate'])),
$row['LeadStatus'],
"Click Here"
);
$i = $i+1;
}
?>
</table>
<table class = "display_table" id = 'campaign_table' style = "display: none; ">
<th>Sr.No.</th>
<th>Lead Id</th>
<th>Campaign Name</th>
<th>Description</th>
<th>Start Date</th>
<th>End Date</th>
<th>Status</th>
<th>Details</th>
<?php
function getleadname($leadid){
include('./server/connection.php');
$selectSQL = "SELECT * FROM `tbl_main_lead_info` WHERE Lead_Id = $leadid";
$result = $conn -> query ($selectSQL);
$i = 1;
while ($row = mysqli_fetch_array($result)){
$leadidandname = $row['Lead_Id']." - ".$row['FirstName']." ".$row['LastName'];
}
return $leadidandname;
}
include('./server/connection.php');
$selectSQL = "SELECT * FROM `tbl_campaign_info`";
$result = $conn -> query ($selectSQL);
$i = 1;
while ($row = mysqli_fetch_array($result)) {
printf( "<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td>%s</td>
</tr>",
$i,
getleadname($row['CampaignLead_Id']),
$row['CampaignName'],
$row['CampaignDescription'],
date('d-m-Y', strtotime($row['CampaignStartDate'])),
date('d-m-Y', strtotime($row['CampaignEndDate'])),
$row['CampaignStatus'],
"Click Here"
);
$i = $i+1;
}
?>
</table>
</div>
</div>
</div>
</div>
</section>
Script is used to change table display style and is inside dashboard.html.
<script>
function viewMainTable(){
var x = document.getElementById('main_lead_table');
var y = document.getElementById('campaign_table');
if (!x.style.display || x.style.display === "none")
{
x.style.display = "block";
y.style.display = "none";
}
else{
x.style.display = "none";
}
}
function viewCampaignTable(){
var x = document.getElementById('campaign_table');
var y = document.getElementById('main_lead_table');
if (!x.style.display || x.style.display === "none")
{
x.style.display = "block";
y.style.display = "none";
}
else{
x.style.display = "none";
}
}
</script>
layout image:
I want to design bootstrap div layout as shown in this picture. I need to have to banner advertisement in the left and right corner. In the middle, I need to have dynamic div s which fetch data from database using PHP. But in the middle when I fetch data as dynamic divs, when number of records increases, the second banner advertisement goes down. How can I solve this?
<div class="col-lg-2" style="padding-top: 50px;">
<div class="card" >
<img src="img/cement_Ad.jpg" height="500" width="300">
</div>
</div>
<!-- 2 -->
<div class="col-lg-8" style="padding-left: 250px;">
<!-- 4 -->
<?php
$sql="select * from services ";
$result = $con->query($sql);
if ($result->num_rows > 0) {
?>
<?php
while($row = $result->fetch_assoc()) {
?>
<div class="col-lg-3" style="padding-top: 40px; padding-left: 20px;">
<section>
<div class="well" >
<div class="card" >
<div class="row ">
<div class="col-md-4">
<img src="img/img1.jpg" height="150px" width="120px">
</div>
<div class="col-md-8 px-3">
<div class="card-block px-3">
<h4 class="card-title"><?php echo $row ['name']; ?></h4>
<div >
<label>Email</label>
<?php echo $row ['email']; ?>
</div>
<div >
<label>Address</label>
<?php echo $row ['address']; ?>
</div>
<div >
<label>District</label>
<?php echo $row ['district']; ?>
</div>
<div >
<label>City</label>
<?php echo $row ['city']; ?>
</div>
<div >
<label>Service</label>
<?php echo $row ['service']; ?>
</div>
<div >
<label>Years of Experience</label>
<?php echo $row ['years']; ?>
</div>
<div>
<label>Details</label>
<?php echo $row ['details']; ?>
</div>
Read More
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php
}
} else {
echo "0 results";
}
$con->close();
?>
</div>
<div class="col-lg-2" style="padding-top: 50px; ">
<div class="card" >
<img src="img/pipe_Ad.jpg" height="500" width="300">
</div>
</div>
This is the result after I used Mr.E-Azam's answer given below
Check Below-
<div class="col-lg-2" style="padding-top: 50px;">
<div class="card" >
<img src="img/cement_Ad.jpg" height="500" width="300">
</div>
</div>
<!-- 2 -->
<div class="col-lg-8">
<!-- 4 -->
<?php
$sql="select * from services ";
$result = $con->query($sql);
if ($result->num_rows > 0) {
?>
<?php
while($row = $result->fetch_assoc()) {
?>
<div class="col-lg-3" style="padding-top: 40px;">
<section>
<div class="well" >
<div class="card" >
<div class="row ">
<div class="col-md-4">
<img src="img/img1.jpg" height="150px" width="120px">
</div>
<div class="col-md-8 px-3">
<div class="card-block px-3">
<h4 class="card-title"><?php echo $row ['name']; ?></h4>
<div >
<label>Email</label>
<?php echo $row ['email']; ?>
</div>
<div >
<label>Address</label>
<?php echo $row ['address']; ?>
</div>
<div >
<label>District</label>
<?php echo $row ['district']; ?>
</div>
<div >
<label>City</label>
<?php echo $row ['city']; ?>
</div>
<div >
<label>Service</label>
<?php echo $row ['service']; ?>
</div>
<div >
<label>Years of Experience</label>
<?php echo $row ['years']; ?>
</div>
<div>
<label>Details</label>
<?php echo $row ['details']; ?>
</div>
Read More
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php
}
} else {
echo "0 results";
}
$con->close();
?>
</div>
<div class="col-lg-2" style="padding-top: 50px; ">
<div class="card" >
<img src="img/pipe_Ad.jpg" height="500" width="300">
</div>
</div>
I could solve the problem just by changing col-lg sizes. The answer is given below
<div class="col-lg-12">
<div class="col-lg-2" >
<div class="card" >
<img src="img/cement_Ad.jpg" height="500" width="300">
</div>
</div>
<div class="col-lg-8">
<?php
$sql="select * from services ";
$result = $con->query($sql);
if ($result->num_rows > 0) {
?>
<?php
while($row = $result->fetch_assoc()) {
?>
<div class="col-lg-6" style="padding-top: 20px;">
<section>
<div class="well" >
<div class="card" >
<div class="row ">
<div class="col-md-4">
<img src="img/img1.jpg" height="150px" width="120px">
</div>
<div class="col-md-8 px-3">
<div class="card-block px-3">
<h4 class="card-title"><?php echo $row ['name']; ?></h4>
<div >
<label>Email</label>
<?php echo $row ['email']; ?>
</div>
<div >
<label>Address</label>
<?php echo $row ['address']; ?>
</div>
<div >
<label>District</label>
<?php echo $row ['district']; ?>
</div>
<div >
<label>City</label>
<?php echo $row ['city']; ?>
</div>
<div >
<label>Service</label>
<?php echo $row ['service']; ?>
</div>
<div >
<label>Years of Experience</label>
<?php echo $row ['years']; ?>
</div>
<div>
<label>Details</label>
<?php echo $row ['details']; ?>
</div>
Read More
</div>
</div>
</div>
</div>
</section>
</div>
<?php
}
} else {
echo "0 results";
}
$con->close();
?>
</div>
<div class="col-lg-2" >
<div class="card" >
<img src="img/pipe_Ad.jpg" height="500" width="300">
</div>
</div>
</div>
I was able to retrieve data from Mysql database however every 4 column I need to close row and start and new row
Following is my HTML code that I am trying to loop through columns and after every 4 columns close the row and keep adding columns from database.
Here is my code (I know this is not PDO and I am trying to learn so I can convert to PDO MySQLi connection)
<div class="row">
<div class="row margin-bottom-20">
<?php
include('dbconnect.php');
$query = "SELECT * FROM selection";
mysql_set_charset("UTF8");
$result = mysql_query($query) or die(mysql_error());
for($i=1; $row = mysql_fetch_array($result); $i++){
?>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-tasks"></i> <strong><?php echo $row['Title']; ?></strong></h3>
</div>
<div class="panel-body">
<p>
<?php echo $row['ContactInfo']; ?><br/>
<img class="img-responsive" src="http://myurl.com/selections/<?php echo $row['file_url']; ?>" >
</p>
</div>
</div>
</div>
<?php
}
?>
I need to add a new for loop but I haven't been successful so far. Thank you for your help.
if($i%4==0)
{
//close the existing div and start new row div here
}
That will start a new row after every 4 iterations
Try this
<?php
include('dbconnect.php');
$query = "SELECT * FROM selection";
mysql_set_charset("UTF8");
$res = mysql_query($query) or die(mysql_error());
while($rows = mysql_fetch_array($res)){
$result[] = $rows;
}
$array = array_chunk($result, 4);
foreach ($array as $value) {
foreach ($value as $row){
?>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-tasks"></i> <strong><?php echo $row['Title']; ?></strong></h3>
</div>
<div class="panel-body">
<p>
<?php echo $row['ContactInfo']; ?><br/>
<img class="img-responsive" src="http://myurl.com/selections/<?php echo $row['file_url']; ?>" >
</p>
</div>
</div>
</div>
<?php
}
}
I'm trying to add a container every 2 iterations. I've implemented a count, but I'm getting weird results as I inspect the page.
Any ideas what may be going on and what I may be doing wrong with the wrapper injection?
<?php
include "includes2014_new/db_conx.php";
$sql ="SELECT * FROM articles WHERE id ORDER BY id DESC LIMIT 5";
$resultsHome = mysqli_query($db_conx,$sql);
$productCount = mysqli_num_rows($resultsHome); // count the output amount
if ($productCount > 0) {
$counter = 1;
while($row = mysqli_fetch_array($resultsHome)){
$id = $row["id"];
$article_title = $row["article_title"];
$category = $row["category"];
$readmore = $row["readmore"];
$author = $row["author"];
$date_added = $row["date_added"];
$content = $row["content"];
$short = substr(strip_tags($content), 0, 80);
if (($counter % 2) === 1) {
$blogList .= '<div class="clearer">';
}
//----------------
if($readmore == ''){
$blogList .= '<div class="col span_6_of_12 postBox textLeft fulltwelvepadfix">
<div class="section miniPad">
<div class="col span_8_of_12">'.$article_title.'</div>
<div class="col span_4_of_12"><img src="images/'.$id.'.jpg" height="80px" width="100px" alt="'.$category.' " /></div>
</div>
<div class="section miniPad">
<div class="col span_12_of_12">'.$date_added.' - '.$author.'</div>
<div class="col span_12_of_12"><p>'.$short.'[...]</p></div>
<div class="section group">Read More</div>
</div>
<div class="comments section group">
<div class="commentsInner">Comments(0)</div>
</div>
</div>';
}
else {
$blogList .= '<div class="col span_6_of_12 postBox textLeft fulltwelvepadfix">
<div class="section miniPad">
<div class="col span_8_of_12">'.$article_title.'</div>
<div class="col span_4_of_12"><img src="images/'.$id.'.jpg" height="80px" width="100px" alt="'.$category.' " /></div>
</div>
<div class="section miniPad">
<div class="col span_12_of_12">'.$date_added.' - '.$author.'</div>
<div class="col span_12_of_12"><p>'.$short.'[...]</p></div>
<div class="section group">Read More</div>
</div>
<div class="comments section group">
<div class="commentsInner">Comments(0)</div>
</div>
</div>';
}
//----------------
if (($counter % 2) === 0) { $blogList .= '</div>'; }
$counter++;
}
}
?>
Try to change
SELECT * FROM articles WHERE id ORDER BY id DESC LIMIT 5
to
SELECT * FROM articles WHERE `id`= '$id' ORDER BY id DESC LIMIT 5