is there a better way for this method? - php

i am trying to make a code that will work like the one below, but i need it to fetch data only once because my code below is fetching more than once and i am afraid it will slow down the server. is there a better way to do the same with the one below. basically the code below will put the list from database into its own div category.
<div class="popular-video">
<h2>Popular</h2>
<ul>
<?php
global $connection;
$sexy = "sexy";
$query = "SELECT `videoname`,`username`,`videourl`,`uploaddate`,`duration`,`views`,`tags` FROM `videolist` WHERE `tags` = ? ";
$stmt = $connection->prepare($query);
$stmt->bind_param("s",$sexy);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($videoname,$username,$videourl,$uploaddate,$duration,$views,$tags);
while ($stmt->fetch()) {
if($username == 'ichigo'){
echo "
<a href='video.php?watch=$videourl'>
<li>
<div class='leftside'>
<img src='' width='100%' height='100%' style='background-color: blue;' >
</div>
<div class='rightside'>
<h4>$videoname</h4>
<p>$username</p>
<p>$views views</p>
<p>$duration</p>
</div>
</li>
</a>
";
}
}
}
?>
</ul>
</div>
<div class="subcription-video">
<h2>Subcription</h2>
<ul>
<?php
global $connection;
$sexy = "sexy";
$query = "SELECT `videoname`,`username`,`videourl`,`uploaddate`,`duration`,`views` FROM `videolist` WHERE `tags` = ? ";
$stmt = $connection->prepare($query);
$stmt->bind_param("s",$sexy);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($videoname,$username,$videourl,$uploaddate,$duration,$views);
while ($stmt->fetch()) {
echo "
<a href='video.php?watch=$videourl'>
<li>
<div class='leftside'>
<img src='' width='100%' height='100%' style='background-color: blue;' >
</div>
<div class='rightside'>
<h4>$videoname</h4>
<p>$username</p>
<p>$views views</p>
<p>$duration</p>
</div>
</li>
</a>
";
}
}
?>
</ul>
</div>
<div class="related-video-by-subcription">
<h2>Related-Video</h2>
<ul>
<?php
global $connection;
$sexy = "sexy";
$query = "SELECT `videoname`,`username`,`videourl`,`uploaddate`,`duration`,`views` FROM `videolist` WHERE `tags` = ? ";
$stmt = $connection->prepare($query);
$stmt->bind_param("s",$sexy);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($videoname,$username,$videourl,$uploaddate,$duration,$views);
while ($stmt->fetch()) {
echo "
<a href='video.php?watch=$videourl'>
<li>
<div class='leftside'>
<img src='' width='100%' height='100%' style='background-color: blue;' >
</div>
<div class='rightside'>
<h4>$videoname</h4>
<p>$username</p>
<p>$views views</p>
<p>$duration</p>
</div>
</li>
</a>
";
}
}
?>
</ul>
</div>

You can make a function and call that function in your HTML.
function foo() {
global $connection;
$sexy = "sexy";
$query = "SELECT `videoname`,`username`,`videourl`,`uploaddate`,`duration`,`views` FROM `videolist` WHERE `tags` = ? ";
$stmt = $connection->prepare($query);
$stmt->bind_param("s",$sexy);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0) {
$stmt->bind_result($videoname, $username, $videourl, $uploaddate, $duration, $views);
while ($stmt->fetch()) {
echo "<a href='video.php?watch=$videourl'>
<li>
<div class='leftside'>
<img src='' width='100%' height='100%' style='background-color: blue;' >
</div>
<div class='rightside'>
<h4>$videoname</h4>
<p>$username</p>
<p>$views views</p>
<p>$duration</p>
</div>
</li>
</a>";
}
}
}
Then just call the function where you want it.
<div class="popular-video">
<h2>Popular</h2>
<ul>
<?php foo(); ?>
</ul>
</div>

You should separate your business logic from presentation logic.
And you can call $stmt->fetch_all() and save the result in a variable and then use this variable in your loops.

Related

echo inside div inside echo [duplicate]

This question already has answers here:
display div inside php using echo
(2 answers)
Closed 4 months ago.
I'm trying to use echo in this code
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$id= $fetch['id'];
?>
<?php echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src=' echo $fetch['video_name']' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
"; ?>
<?php
}
?>
I'm getting this error Parse error: syntax error, unexpected string content "", expecting "-" or identifier or variable or number in C:\xampp\htdocs\desk\gallery.php on line 572
Why this error?
.................................................................
You can escape the string and concatenate the variable in the place your hoping to have it like this:
<img src='". $fetch['video_name'] ."' alt=''>
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$id= $fetch['id'];
?>
<?php echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src='". $fetch['video_name'] ."' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
"; ?>
<?php
}
?>
You can't use echo inside an echo or should I say string statement.
What you have to do is variable substitution like:
echo 'This is my variable '.$x.'.';
Or...
echo "This is my variable $x.";
In your code:
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)){
$id= $fetch['id'];
$video_name = $fetch['video_name'];
?>
<?php echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src='$video_name' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
"; ?>
<?php
}
?>
Also you can ditch the <?php ?>:
<?php
require 'connect.php';
$query = mysqli_query($conn, "SELECT * FROM `videos`") or die(mysqli_error());
while($fetch = mysqli_fetch_array($query)) {
$id = $fetch['id'];
$video_name = $fetch['video_name'];
echo "
<li class='col-lg-4 col-md-6 col-dm-12'>
<div class='da-card box-shadow'>
<div class='da-card-photo'>
<img src='$video_name' alt=''>
<div class='da-overlay'>
<div class='da-social'>
<h4 class='mb-10 color-white pd-20'></h4>
<ul class='clearfix'>
<li>
<a href='' data-fancybox='images'><i class='fa fa-picture-o'></i></a>
</li>
<li>
<a href='#'><i class='fa fa-link'></i></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</li>
";
}

Something wrong while deleting a row in sql table on clicking a button

Trying to delete a row from my SQL table in my shopping cart page,but my code deletes all the rows from the table on clicking a button.Even when I update quantity of the one product the quantity of all the products are changing.The answer might be the same for these two issues.Could you please review my code and tell me where I've done wrong.
Thankyou in advance
<?php
include "header.php";
require "includes/connect.php";
require "includes/product.php";
class Cartitem{
public function fetch_cart(){
global $pdo;
$query = $pdo->prepare("SELECT * FROM cart_items WHERE user_id = ?");
$query->bindvalue(1, $_SESSION['user_id']);
$query -> execute();
return $query->fetchAll();
}
}
$cartitem= new Cartitem;
$cartitems=$cartitem-> fetch_cart();
?>
<div class="cart">
<div class = "container">
<div class="col-md-9 cart-items">
<h1 class="cart-items-h1">Cart</h1>
<hr>
<?php foreach($cartitems as $cartitem) { ?>
<div class="cart-header">
<h3>
<?php echo $cartitem['product_name'] ; ?></h3>
<br>
<?php
if(isset($_POST['delete'])){
$query = $pdo->prepare('DELETE FROM cart_items WHERE product_id=?');
$query->bindValue(1 , $cartitem['product_id']);
$query->execute();
}
?>
<form method = "POST" action="">
<button type="submit" class="close btn btn-default" name="delete"><span class="glyphicon glyphicon-remove " aria-hidden="true"></span></button>
</form>
<div class="cart-sec simpleCart_shelfItem">
<div class="cart-item cyc">
<img src="Tiger.jpg" class="img-responsive" alt=" No image"/>
</div>
<div class="cart-item-info">
<ul class="item-properties">
<li>
<form action="" method="post">
<?php
if(isset($_POST['qty'])){
$quantity=$_POST['qty'];
$query = $pdo->prepare('UPDATE cart_items SET quantity= ? WHERE product_id=?');
$query->bindValue(1 , $quantity);
$query->bindValue(2 , $cartitem['product_id']);
$query->execute();
}
?>
<select class="quantity" name="qty">
<?php
echo '<option >'.$cartitem['quantity'].'</option>';
for($q = 1 ; $q<10 ; $q++){
echo '<option >'.$q.'</option>';
}
?>
</select>
<button type="submit" class="update" name="update">Update</button>
</li>
<li><p>Rs.<?php echo $cartitem['price']; ?></p></li>
</ul>
<div class="delivery">
<p>Service Charges : Rs.190.00</p>
<span>Delivered in 2-3 bussiness days</span>
<div class="clearfix"></div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<?php }?>
</div>
This is (productpage.php) from where I'm storing the values to the cart table.Probably not so important to this issue. If yes
<?php
ob_start();
include ('header.php');
require('includes/connect.php');
require('includes/product.php');
$product = new Product;
if(isset ($_GET['id'])) {
$id = $_GET['id'];
$data = $product -> fetch_data($id);
if(isset($_POST['add'])){
if (isset($_SESSION['logged_in'])) {
$query = $pdo->prepare("SELECT product_id FROM cart_items WHERE product_id= ?");
$query -> bindValue(1, $id);
$query ->execute();
$num=$query->rowCount();
if($num == 0){
if(isset($_POST['qty'])){
$qty=$_POST['qty'];
}
$query = $pdo -> prepare("INSERT INTO cart_items(product_id , user_id, quantity,price,product_name) VALUES (?,?,?,?,?)");
$query -> bindValue(1, $id);
$query -> bindValue(2, $_SESSION['user_id']);
$query -> bindValue(3, $qty);
$query -> bindValue(4, $data['new_price']);
$query -> bindValue(5, $data['product_name']);
$query ->execute();
header('location:cart.php');
}
else{
echo " The product is already in your Cart";
}
}
else{
header('location:Login Page.php');
}
}
?>
<div class="showcase-grid">
<div class="container ">
<?php if(isset($error)){ ?>
<small style = "color : #aa0000"; ><?php echo $error ?></small>
<br><br>
<?php } ?>
<div class="col-md-8 showcase" id="showcase-div">
<div class="img-showcase" >
<br>
<div id="myCarousel" class="carousel slide text-center" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class=" img-responsive"></li>
<li data-target="#myCarousel" data-slide-to="1" class="img-responsive"></li>
<li data-target="#myCarousel" data-slide-to="2" class="img-responsive"></li>
<li data-target="#myCarousel" data-slide-to="3" class="img-responsive"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img class="slide-img" src="images/product2.jpg" alt="jwellery" >
</div>
<div class="item">
<img src="images/product3.jpg" alt="jwellery">
</div>
<div class="item">
<img src="images/product4.jpg" alt="jwellery" >
</div>
<div class="item">
<img src="images/product5.jpg" alt="jwellery" >
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
<br>
</div>
</div>
<div class="col-md-4 showcase1 ">
<div class="showcase-rt-top">
<div class = "row">
<div class ="col-md-12">
<br>
<div class="pull-left Product-name">
<h3><?php echo $data['product_name']; ?></h3>
<br>
</div>
</div>
<br><br><br>
<div class ="col-xs-4 price">
<h4>Rs.<?php echo $data['new_price']; ?></h4>
</div>
<div class ="col-xs-4 oldprice text-left">
<s><h4 class="text-left">Rs.<?php echo $data['old_price']; ?></h4></s>
</div>
<div class ="col-xs-4">
<div class="pull-right rating-stars pull-left">
<h4><span class="label label-warning">3.5 <span class="glyphicon glyphicon-star star-stn" aria-hidden="true"></span></span></h5>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<hr class="featurette-divider">
<div class="shocase-rt-bot">
<div class="col-xs-6 discount">
<?php
$discount = (($data['old_price'] - $data['new_price'])/$data['old_price'])*100;
echo round($discount) . '% off ';
?>
</div>
<form action = "" method="post" class="form-inline">
<div class="col-xs-6">
<div class="float-qty-chart">
<!-- <label class=" option">quantity:</label>-->
<select id= "select" class="form-control qnty-chrt" name="qty" >
<option value="1">quantity</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
<div class="clearfix"></div>
</div>
</div>
<ul class="ul_list">
<li class="ad-2-crt simpleCart_shelfItem">
<button type="submit" class="btn item_add" name="add" >Add To Cart</button>
<button type="submit" class="btn item_add" name="buy-now">Buy Button</button>
</li>
</ul>
<br>
</div>
</form>
<div class="features" >
<h3>product details</h3>
<ul>
<li><?php echo nl2br($data['brief_description']); ?></li>
</ul>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<?php
}
else{
header('location: index.php');
exit();
}
Include ('footer.php');
?>
This is the product.php
<?php
class Product {
public function fetch_all() {
global $pdo;
$query = $pdo->prepare("SELECT * FROM ear_rings_list");
$query -> execute();
return $query->fetchAll();
}
public function fetch_data($pid) {
global $pdo;
$query = $pdo->prepare("SELECT * FROM ear_rings_list WHERE listing_id = ?");
$query->bindValue(1, $pid);
$query->execute();
return $query->fetch();
}
}
Actually you are working with an foreach loop
Just check here
<?php foreach($cartitems as $cartitem) { ?>
if(isset($_POST['delete'])){
$query = $pdo->prepare('DELETE FROM cart_items WHERE product_id=?');
$query->bindValue(1 , $cartitem['product_id']);
$query->execute();
}
if(isset($_POST['qty'])){
$quantity=$_POST['qty'];
$query = $pdo->prepare('UPDATE cart_items SET quantity= ? WHERE product_id=?');
$query->bindValue(1 , $quantity);
$query->bindValue(2 , $cartitem['product_id']);
$query->execute();
}
<?php }?>
Here you are just checking the isset($_POST['delete']) which will be true for each $cartitem['product_id'] that's why your each row is deleting and updating.
Solution:-
Use this code
<?php
include "header.php";
require "includes/connect.php";
require "includes/product.php";
class Cartitem
{
public function fetch_cart()
{
global $pdo;
$query = $pdo->prepare("SELECT * FROM cart_items WHERE user_id = ?");
$query->bindvalue(1, $_SESSION['user_id']);
$query->execute();
return $query->fetchAll();
}
}
$cartitem = new Cartitem;
$cartitems = $cartitem->fetch_cart();
?>
<div class="cart">
<div class="container">
<div class="col-md-9 cart-items">
<h1 class="cart-items-h1">Cart</h1>
<hr>
<?php
if (isset($_POST['qty']) && isset($_POST['product_id'])) {
$quantity = $_POST['qty'];
$product_id = $_POST['product_id'];
$query = $pdo->prepare('UPDATE cart_items SET quantity= ? WHERE product_id=?');
$query->bindValue(1, $quantity);
$query->bindValue(2, $product_id);
$query->execute();
}
?>
<?php
if (isset($_POST['delete']) && isset($_POST['product_id'])) {
$product_id = $_POST['product_id'];
$query = $pdo->prepare('DELETE FROM cart_items WHERE product_id=?');
$query->bindValue(1, $product_id);
$query->execute();
}
?>
<?php foreach($cartitems as $cartitem) { ?>
<div class="cart-header">
<h3>
<?php echo $cartitem['product_name']; ?></h3>
<br>
<form method="POST" action="">
<input type="hidden" value="<?php $cartitem['product_id'] ?>" name="product_id">
<button type="submit" class="close btn btn-default" name="delete"><span class="glyphicon glyphicon-remove " aria-hidden="true"></span></button>
</form>
<div class="cart-sec simpleCart_shelfItem">
<div class="cart-item cyc">
<img src="Tiger.jpg" class="img-responsive" alt=" No image"/>
</div>
<div class="cart-item-info">
<ul class="item-properties">
<li>
<form action="" method="post">
<input type="hidden" value="<?php $cartitem['product_id'] ?>" name="product_id">
<select class="quantity" name="qty">
<?php
echo '<option >' . $cartitem['quantity'] . '</option>';
for ($q = 1; $q < 10; $q++) {
echo '<option >' . $q . '</option>';
}
?>
</select>
<button type="submit" class="update" name="update">Update</button>
</form>
</li>
<li><p>Rs.<?php echo $cartitem['price']; ?></p></li>
</ul>
<div class="delivery">
<p>Service Charges : Rs.190.00</p>
<span>Delivered in 2-3 bussiness days</span>
<div class="clearfix"></div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
<?php }?>
</div>
Changes :-
I just make an hidden input field for $cartitem['product_id'] here <input type="hidden" value="<?php $cartitem['product_id'] ?>" name="product_id">
and placed the delete and update query out side the foreach loop.

distinguish between divs after fetch data from database

how do i distinguish between $tags, i need to separate video with tags sexy and video with tags new. i need to put $tags = $sexy to be in div sexydiv and so is the other divs. the code i made below will only make each list. i need to make it look like youtube home page, where suggestion video and trending video are separate in 2 divs.
<div class="suggested-video">
<h2>Suggestion for you</h2>
<ul>
<?php
global $connection;
$sexy = "sexy";
$new = "new";
$query = "SELECT `videoname`,`username`,`videourl`,`uploaddate`,`duration`,`views`,`tags` FROM `videolist` WHERE `tags` = ? ";
$stmt = $connection->prepare($query);
$stmt->bind_param("s",$sexy);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($videoname,$username,$videourl,$uploaddate,$duration,$views,$tags);
while ($stmt->fetch()) {
if($tags == $sexy){
echo "
<div class='sexydiv'>
<ul>
<a href='video.php?watch=$videourl'>
<li>
<div class='leftside'>
<img src='' width='100%' height='100%' style='background-color: blue;' >
</div>
<div class='rightside'>
<h4>$videoname</h4>
<p>$username</p>
<p>$views views</p>
<p>$duration</p>
<p>$tags</p>
</div>
</li>
</a>
</ul>
</div>
";
}
if($tags == $new){
echo "
<div class='newdiv'>
<ul>
<a href='video.php?watch=$videourl'>
<li>
<div class='leftside'>
<img src='' width='100%' height='100%' style='background-color: blue;' >
</div>
<div class='rightside'>
<h4>$videoname</h4>
<p>$username</p>
<p>$views views</p>
<p>$duration</p>
<p>$tags</p>
</div>
</li>
</a>
</ul>
</div>
";
}
}
}
?>
</ul>
</div>

How to display 4 columns continuously in a loop with Bootstrap and SQL query

I want to display 4 images result of a SQL query for each row with Bootstrap. How can I do it with a loop in PHP?
<div class="row">
<?php
$query = "SELECT * FROM table WHERE nombre='x' ORDER BY nombre";
$consulta = mysql_query($query, $conexion);
while ($data = mysql_fetch_assoc($consulta)) { ?>
<div class='col-md-3 portfolio-item'>
<a href='img/<?php echo $data['imagen']; ?>'>
<img class='img-responsive' src='img/<?php echo $data['imagen']; ?>' alt='<?php echo $data['nombre']; ?>'>
</a>
<div class='panel panel-default'>
<div class='panel-body'>
<?php echo $data['nombre']; ?>
</div>
</div>
</div>
<?php } ?>
</div>
Close and open a new row -
<div class="row">
<?php
$query = "SELECT * FROM table WHERE nombre='x' ORDER BY nombre";
$consulta = mysql_query($query, $conexion);
$i = 1;
while ($data = mysql_fetch_assoc($consulta)) { ?>
<div class='col-md-3 portfolio-item'>
<a href='img/<?php echo $data['imagen']; ?>'>
<img class='img-responsive' src='img/<?php echo $data['imagen']; ?>' alt='<?php echo $data['nombre']; ?>'>
</a>
<div class='panel panel-default'>
<div class='panel-body'>
<?php echo $data['nombre']; ?>
</div>
</div>
</div>
<?php
if($i % 4 === 0) echo "</div><div class='row'>"; // close and open a div with class row
$i++; // increment
}
?>
</div>

SQLSTATE[HY000] error,cant connect to mysql server error occurs when i tried to connect the local database in PDO using phpmyadmin

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

Categories