i making paging from table using the following code my table name is category and 2nd one posts and the one with sit setting setting
<div id="wrap">
<div class="container" style="margin-top:50px;">
<div class="row">
<?php
$per_page =8;
if (!isset($_GET['page']))
{
$page = 1;
}
else
{
$page = (int)$_GET['page'];
}
$start_f = ($page-1) * $per_page;
$query = mysqli_query($conn, " SELECT * FROM `posts` p INNER JOIN `users` u
WHERE p.p_author = u.u_id AND `p_category` = '$_GET[category]' ORDER BY `p_id` DESC LIMIT $start_f , $per_page" );
while ( $post = mysqli_fetch_assoc($query)) {
# code...
?>
<div class="col-xs-12 col-sm-6 col-md-3" style="margin-top: 20px;">
<div class="col-item" >
<div class="post-img-content">
<img src="<?php echo $post['p_image']; ?>" style="width: 100%; height: 100%;" class="img-responsive" />
<span class="post-title">
<b class="pull-left"><?php echo $post['p_title']?></b>
</span>
</div>
<div>
<div class="info" >
<div class="row ">
<div class="col-md-12"></div>
<div class="price col-md-6">
<h5><b><?php echo $post['p_category'];?></b></h5>
</div>
<div class=" hidden-sm col-md-6">
<h5 style="text-align: right;"><a href="admin-cp/profile.php?user=<?php echo $post['u_id']; ?>"><b ><?php echo
$post['u_name'];?></b></a></h5>
</div>
<div class=" hidden-sm col-md-12">
<h5><b>Date : </b><?php echo $post['p_date'];?></h5>
</div>
</div>
<div class="separator clear-left">
<p style="text-align: left;">
<i class="fa fa-eye"></i>View</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
<?php
}
$page_sql = mysqli_query($conn, "SELECT * FROM
`posts` WHERE `p_category` = '$_GET[category]'");
$count_page = mysqli_num_rows($page_sql);
$total_page = ceil($count_page/$per_page); /// cail for make value int
?>
<nav class="text-center">
<ul class="pagination">
<?php
for($i = 1 ; $i <= $total_page; $i++)
{
echo '<li '.($page==$i ? 'class="active"' : '').' >'.$i.'</li>';
}
?>
</ul>
</nav>
</div>
this http://localhost/p/category.php?category=Computers work and get me the first page but that http://localhost/p/category.php?category=Computers?page=1 give me 0 result
pleas help me it's very important to me
You link concatenation is wrong, use & instead of ? again:
<?php
}
$page_sql = mysqli_query($conn, "SELECT * FROM
`posts` WHERE `p_category` = '$_GET[category]'");
$count_page = mysqli_num_rows($page_sql);
$total_page = ceil($count_page/$per_page); /// cail for make value int
?>
<nav class="text-center">
<ul class="pagination">
<?php
for($i = 1 ; $i <= $total_page; $i++)
{
echo '<li '.($page==$i ? 'class="active"' : '').' >'.$i.'</li>';
}
?>
Related
How do i disable and enable an anchor tag based on order_status condition? I want to make my receipt button only be able to click when the order_status been updated to ($irow['order_status'] == 5. It would be much appreciated if you all can provide me a code demo to show me how should I implement this using jquery. Thanks!
<div class="container mt-3 mb-5">
<div class="row form-group">
<?php
$total_price = 0.00;
$total_quantity = 0;
$sql = "SELECT *, sum(purchase_price) purchase_price, sum(quantity) quantity FROM ordered_items WHERE user_id = '$user_id' GROUP BY order_id ORDER BY order_datetime DESC";
$query = $conn->query($sql);
if (!mysqli_num_rows($query)) {
echo '
<div class="col-12 text-center">
<div class="alert alert-danger">
<strong><span class="iconify" data-icon="ic:round-remove-shopping-cart" data-width="30px" data-height="30px" data-inline="false"></span> You have no order</strong>
</div>
</div>
';
} else {
while ($row = $query->fetch_assoc()) {
$total_price = $row['purchase_price'];
if($total_price < 500.00 && $row['item_deliver_method'] == 'Delivery'){
$grand_total = $total_price + 10.00;
}else{
$grand_total = $total_price;
}
$total_quantity = $row['quantity'];
//$grand_total = $row['grand_total'];
?>
<div class="col-12 form-group orderidfocus">
<div class="product-wrapper" id="<?php echo $row['order_id']; ?>">
<p class="pl-2 pt-2 pr-2">OrderID: <?php echo $row['order_id']; ?>
</br><?php echo $row['item_deliver_method']; ?> Date: <?php echo $row['delivery_date']; ?></p>
<hr style="border: 0.5px dashed #DBDBDB;">
<?php
$isql = "SELECT * FROM ordered_items LEFT JOIN products ON ordered_items.product_id = products.id WHERE ordered_items.order_id = '".$row['order_id']."' ";
$iquery = $conn->query($isql);
while ($irow = $iquery->fetch_assoc()) {
if($irow['order_status'] == 1) {
$order_status = '<div class="badge-secondary font-italic p-1">Waiting for Response </div>';
}
if($irow['order_status'] == 2) {
$order_status = '<div class="badge-warning font-italic p-1">Preparing</div>';
}
if($irow['order_status'] == 3) {
$order_status = '<div class="badge-info font-italic p-1">In Delivery</div>';
}
if($irow['order_status'] == 4) {
$order_status = '<div class="badge-danger font-italic p-1">Ready to Pick up</div>';
}
if($irow['order_status'] == 5) {
$order_status = '<div class="badge-success font-italic p-1">Completed</div>';
}
?>
<div class="row h-100 pl-2 pr-2 form-group">
<div class="col-12">
<small class="float-right"><?php echo $order_status; ?></small>
</div>
<div class="col-3 my-auto form-group">
<img class="order-page-img-thumbnail" src="images/product-main/<?php echo $irow['product_photo']; ?>" alt="">
</div>
<div class="col-5 pl-0 pr-0 my-auto form-group">
<div class="product-title"><?php echo $irow['product_title']; ?></div>
</div>
<div class="col-4 pl-0 my-auto form-group">
<div class="product-price" style="text-align: right;">
RM<?php echo $irow['product_price']; ?>/<?php echo $irow['product_quantity']; ?><br>
<span style="color: #00644C;">X<?php echo $irow['quantity']; ?></span>
</div>
</div>
</div>
<?php } ?>
<hr style="border: 0.5px dashed #DBDBDB;">
<div class="row justify-content-end pl-2 pr-1">
<div class="col-3 my-auto form-group pr-0">
<p class="cat-title" style="text-align: left;font-size: 13px;">Qty: <?php echo $total_quantity; ?>KG</p>
</div>
<div class="col-5 my-auto form-group pl-0">
<p class="cat-title" style="text-align: right;font-size: 13px;">Amount: RM<?php echo number_format($grand_total,2); ?></p>
</div>
<div class="col-4 form-group pull-right text-center pl-0">
<a id="receiptbtn" target="_blank" href="receipt.php?order_id=<?php echo $row['order_id']; ?>" class="btn addtocart" style="font-size: 12px;"><span class="iconify" data-icon="bx:bx-download" data-inline="false"></span> Receipt</a>
</div>
</div>
</div>
</div>
<?php
}
}
?>
i use Bootstrap’s cards and php but i don't want to show a card per line
screen 1
i want to show Bootstrap’s card two per line like this:
screen 2
what can i do ?
this is my code:
<?php
$no_pharmacies_par_page = 5;
if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$ph = $no_pharmacies_par_page * $page - $no_pharmacies_par_page;
$sql_select_pharma = "SELECT * FROM pharmacies WHERE pharmacie_garde = 1 ORDER BY id desc LIMIT {$ph} ,{$no_pharmacies_par_page} ";
$res_sql_select_pharma = mysqli_query($dbconnection, $sql_select_pharma);
while ($rowpharma = mysqli_fetch_assoc($res_sql_select_pharma))
{
$id_pharma = $rowpharma['id'];
$nom_pharma = $rowpharma['nom_pharma'];
$pharma_syndicat = $rowpharma['nom_syndicat'];
$date_debut = $rowpharma['date_deb'];
$pharma_modif_date = $rowpharma['date_fin'];
$image_pharmacie = $rowpharma['image_pharmacie'];
$adresse_pharmacie = $rowpharma['adresse_pharma'];
$tel_pharmacie = $rowpharma['tel_pharmacie'];
$pharma_garde = $rowpharma['pharmacie_garde'];
$email_pharmacie = $rowpharma['email_pharmacie'];
?>
<div class="card-deck">
<div class="card">
<img class="card-img-top" src="admin/images/pharmacides/<?php echo $image_pharmacie; ?>" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><?php echo $nom_pharma; ?></h5>
<p class="card-text"><?php echo substr($adresse_pharmacie, 0, 80) . "...";?></p>
</div>
<div class="card-footer">
<small class="text-muted"><?php echo $date_debut; ?></small>
</div>
</div>
</div>
<?php } ?>
Replace your html code with this and it'll do the required job.
<div class="container">
<div class="row">
<!-- Put Your For loop here to loop through your data -->
<div class="col-6">
<div class="card-deck">
<div class="card">
<img class="card-img-top" src="admin/images/pharmacides/<?php echo $image_pharmacie; ?>" alt="Card image cap">
<div class="card-body">
<h5 class="card-title"><?php echo $nom_pharma; ?></h5>
<p class="card-text"><?php echo substr($adresse_pharmacie, 0, 80) . "...";?></p>
</div>
<div class="card-footer">
<small class="text-muted"><?php echo $date_debut; ?></small>
</div>
</div>
</div>
</div>
</div>
</div>
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'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
I tried to connect the page with phpmyadmin in local server using PDO but i couldnt connect to it and i'm getting SQLSTATE error can anyone please help me through it.
config.php:
<?Php
$dbhost_name = "localhost";
$database = "seekouttech";// database name
$username = "root"; // user name
$password = ""; // password
//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
pagination1.php
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<?php include "./includes/menu_include.php";
$t=$_GET['id2'];
echo $t;
$nws_id = $t;
?>
<?Php
include "config.php"; // All database details will be included here
$page_name="pagination1.php";
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}
$eu = ($start - 0);
$limit = 10; // No of records to be shown per page.
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$query2=" SELECT * FROM comment where newsid='$t' ";
$count=$dbo->prepare($query2);
$count->execute();
$nume=$count->rowCount();
$query=" SELECT * FROM comment limit $eu, $limit ";
foreach ($dbo->query($query) as $row) {
echo $row[name];
}
if($nume > $limit ){
if($back >=0) {
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>";
}
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
$l=$l+1;
}
if($this1 < $nume) {
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";}
?>
<div class="main-content-top">
<div class="main-wrapper">
<div class="row">
<div class="large-6 columns">
<h2>Blog</h2>
</div>
<div class="large-6 columns">
<ul class="breadcrumbs right" style="font- size:18px;">
<li style="text-transform:none;">You are here: </li>
<li>HOME</li>
<li><span>BLOG</span></li>
<li><span>BLOG DETAILS</span></li>
</ul>
</div>
</div>
</div>
</div>
<div class="main-wrapper">
<div class="content_wrapper">
<div class="row">
<div class="large-8 columns">
<article class="post single-post">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result_comment=mysql_query("select newsid from comment where newsid='$t' ");
$count = mysql_num_rows($result_comment);
$result = mysql_query("SELECT * FROM news where newsid='$t'");
while($row = mysql_fetch_array($result))
{
?>
<div class="post_img">
<img class="post_image" src="display_image.php?
pic_id=<?php echo $row['id']; ?>" alt="post title">
<ul class="meta">
<li><i class="icon-comment"></i><?php echo $count." comments";?></li>
<li><i class="icon-calendar"></i><?php echo $row['date']; ?></li>
</ul>
</div>
<h3><?php echo $row['heading']?></h3>
<p class="post_text" style="text-align:justify;"><?php echo $row['description']?></p>
</article>
<div class="comments">
<h4 class="color comment_count"><?php echo $count." comments";?></h4>
<div class="com_meta">
<span class="user_name"><br>
<?php
$result_comment1=
mysql_query("select * from comment where newsid='$t' ORDER BY id DESC ");
while($row9 = mysql_fetch_array($result_comment1))
{
echo "<b>".$row9['name']."</b>";
?><span class="com_date"><?php echo $row9['date'];?></span><br>
<p class="com_text"><?php echo $row9['comment'];?>
</p>
<?php }
?>
</div>
<div class="com_content">
</div>
</div>
</div>
<?php
}mysql_close();
?>
<aside class="large-4 columns">
<div class="widgets">
<div class="section-container tabs" data-section="tabs">
<section class="section">
<p class="title"><i class="icon-random"></i> </p>
<div class="content">
<marquee direction="up" scrollamount="1">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result2=mysql_query("SELECT * FROM news ORDER BY id ASC limit 4");
while($row2 = mysql_fetch_array($result2))
{
$id3=$row2['newsid'];
?>
<p style="margin-top:-6px;"><a href="blog-details.php?id2=<?php echo $id3;?>">
<?php
$desc2=$row2['heading'];
echo SUBSTR($desc2,0,40);
echo "....";
?> </a>
</p>
<?php
}mysql_close();
?>
</marquee>
</div>
</section>
<section class="section">
<p class="title"><i class="icon-comment-alt"></i></p>
<div class="content">
<ul class="categories">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result_comment=mysql_query("select * from comment where newsid='$t' ");
//echo $t;
while($row9 = mysql_fetch_array($result_comment))
{
echo '<br>'.$row9['comment'];?> ----<h7 style="color:#000000; font:bold">
<?php
echo $row9['name'];
?>
</h7>
<?php
}
mysql_close();
?>
</ul>
</div>
</section>
</div>
</div>
<div class="widgets" style="clear:both;">
<h3>Tags</h3>
<ul id="tags">
<li>App Development</li>
<li>Web Design</li>
<li>User Interface</li>
<li>Branding</li>
</ul>
<div class="clearfix"></div>
</div>
<div class="widgets">
<h3>Services</h3>
<ul id="example1" class="accordion">
<li>
<div class="handle"><span><i></i>
</span>Logo Design </div>
</li>
<li>
<ul class="panel loading">
<li>How about…</li>
<li>… a list …</li>
<li>… of items?</li>
</ul>
</li>
<li>
<p class="panel loading">An image in a paragraph.</p>
</li>
<li><div class="handle"><span><i></i>
</span>On-line Marketing</div>
</li>
<div class="widgets">
<?php
mysql_connect("localhost","root","");
mysql_select_db("seekouttech");
$result5=mysql_query("SELECT * FROM quoteday ORDER BY id DESC limit 1");
while($row5 = mysql_fetch_array($result5))
{
?>
<h3>Quote of the Day</h3>
<div class="panel">
<p>
<?php echo'"';
echo $row5['quoteoftheday'];
echo '"';
?>
</p>
</div>
<?php
}
mysql_close();
?>
</div>
</aside>
</div>
</div>
</div>
<?php include "./includes/footer_section.php";?>
This is the code where i want to implement pagination and i want to retrieve all the comments that i fetched from db using mysql.
The obvious answer is that mysql is not running.
Please try connecting to mysql on the command line to confirm it is running