How to include a filed to while loop query? - php

I have used foreach in my query for retrieving data but in here in the middle of the page I have a field $row['RemoteEmployeeID'] which is out of while loop and I am unable to include it to while loop, if I include it so my header is going to be repeated with each and every record.
Here is my code:
<html>
<head>
</head>
<body>
<div class="wrapper">
<div class="header">
<?php
error_reporting('0');
ob_start();
session_start();
if(!isset($_SESSION['email']))
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL= ../../spd/myaccount.php">';
exit();
}
else
{
$email = $_SESSION['email'];
require_once('../../Admin Panel/db.php');
$query = "SELECT
properties.PropertyID,
properties.PropertyType,
properties.PropertyDealType,
properties.Status,
properties.PropostedPrice,
properties.PropertyStatus,
properties.RemoteEmployeeEmail,
properties.PropertyDealerName,
properties.PropertyOwnerName,
remoteemployees.RemoteEmployeeID
FROM remoteemployees, properties
WHERE remoteemployees.RemoteEmployeeEmail = properties.RemoteEmployeeEmail
AND properties.RemoteEmployeeEmail = '".$email."'
AND properties.Status= 'Active'
AND properties.PropertyStatus= 'APPROVED'
ORDER BY properties.PropertyID
";
$query_run = $connection->query($query);
if( $connection->error ) exit( $connection->error );
while($res=$query_run->fetch_assoc()) {
$count = $query_run->num_rows; // Taking the number of queries returened by the result
$array[] = $res;
}
?>
<div style="float:left;"><font color="#000000">Welcome: <?php echo $_SESSION['email']; ?>
</font>
</div>
<div style="float:right; color:#999; width:600px; margin-left:155px;">
My Contract Copy
My Property List
My Trans.History
<a href="Remote Employee profile.php?RemoteEmployeeid=<?php echo $row['RemoteEmployeeID'] ?>" class="button" >My Profile</a>
Logout
</div>
</div>
<div class="Labelcon">
<div class="Label">Property ID</div>
<div class="Label">Property Type</div>
<div class="Label">Property Deal Type</div>
<div class="Labelowner">Property Owner</div>
<div class="Labeldealer">Property Dealer</div>
<div class="Label">Proposted Price</div>
<div class="Label">Property Status</div>
</div>
<?php
// Here is the start of the loop
foreach($array as $row) { ?>
<div class="Valuecon">
<div class="Value"><?php echo $row['PropertyID'] ?></div>
<div class="Value"><?php echo $row['PropertyType'] ?></div>
<div class="Value"><?php echo $row['PropertyDealType']?></div>
<div class="Valueowner"><?php echo $row['PropertyOwnerName'] ?></div>
<div class="Valuedealer"><?php echo $row['PropertyDealerName'] ?></div>
<div class="Value"><?php echo $row['PropostedPrice'];?></div>
<div class="Value"><?php echo $row['PropertyStatus'];?></div>
</div>
<?php
if($query_run->num_rows == 0)
{
echo 'No Records Found';
}
}}
?>
</div>
<p></p>
<center>
<?php $queryemail= "SELECT SUM(transactions.EarnAmount) AS TotalEarn, transactions.TaxDeduction,
SUM(transactions.AmountPaid) AS TotalPaid from transactions WHERE transactions.RemoteEmployeeID = ".$row['RemoteEmployeeID']." limit 1"; ?>
<div class="Amountpayablepaid">
<div class="amountpayable">
<div class="aclabel">Earn Amount:</div>
<div class="acvalue">
<?php
$queryemail_run = $connection->query($queryemail);
if( $connection->error ) exit( $connection->error );
while($row=$queryemail_run->fetch_assoc())
{
?>
<div class="USD">
<?php echo 'USD '.$row['TotalEarn']; ?>
</div>
</div>
<br>
<br>
</div>
<div class="amountpaid">
<div class="acpaidlable">Tax Deduction:</div>
<div class="acpaidvalue">
<div class="USDpaid"><?php echo $row['TaxDeduction'].' %'; ?></div>
</div>
</div>
<div class="amountpaid" style="margin-top:22px;">
<div class="acpaidlable">Amount Paid:</div>
<div class="acpaidvalue">
<div class="USDpaid"><?php echo 'USD '.$row['TotalPaid'];}?></div>
</div>
</div>
</div>
</center>
</body>
</html>

Its Simple:
$RemoteEmp = null;
$count = $query_run->num_rows;
while($res=$query_run->fetch_assoc()) {
$array[] = $res;
$RemoteEmp = $res["RemoteEmployeeID"];
}
Now :
<a href="Remote Employee profile.php?RemoteEmployeeid=<?php echo $RemoteEmp; ?>" class="button" >My Profile</a>

Related

display 4 book details per row in image slider

I have coded this image slider that moves the image and it's details using the cursor.
I want to fetch data from database and display 4 books images with their details in each row I have tried this code but all the data have displayed in one row only.
Also if this does not take much of your time I want to make only 7 rows per page (28 books) and add numbers at the bottom of the page to move to the next 7 rows.
this is my try :
<html>
<body>
<div class="popular_causes_area section_padding">
<div class="container"> <div class="row">
<div class="col-lg-12">
<div class="causes_active owl-carousel">
<?php
try{
require('connection.php');
$sql1="select * from books ";
$rs=$db->query($sql1);
$db =null;
} catch(PDOException $ex) {
die ("Error Message ".$ex->getMessage()); }
$i=0;
while ($books = $rs->fetch()){
$i++;
$bpic = $books[2];
$btitle= $books[3];
$bq= $books[4];
$bstatus = $books[5];
$bdesc = $books[6];
$bnumber = $books[7];
$bcity = $books[8];
if ($i % 3 == 1) {
echo "<li>"; ?>
<div class="single_cause">
<div class="thumb">
<?php
if ($bpic == "" ) {
echo "<img src='img/default-image.png'
height=450px'>";
} else {
echo "<img src='img/$bpic' placeholder='nooooo'
height=450px alt=''>";
}?>
</div>
<div class="causes_content">
<div class="balance d-flex justify-content-between align-items-center">
<span>Tell:<?php echo $bnumber; ?> </span>
<span><?php echo $bcity; ?> </span>
</div>
<h4><?php echo $btitle; ?> </h4>
<p><?php echo $bdesc; echo "<br>
condation:".$bstatus; ?> </p>
</div>
</div>
</li>
<?php
} ////end of first if
if ($i % 3 == 0) {
echo "<li>"; ?>
<div class="single_cause">
<div class="thumb">
<?php
if ($bpic == "" ) {
echo "<img src='img/default-image.png' height=450px'>";
} else {
echo "<img src='img/$bpic' placeholder='nooooo' height=450px alt=''>"; ?>
</div>
<div class="causes_content">
<div class="balance d-flex justify-content-between align-items-center">
<span>Tell:<?php echo $bnumber; ?> </span>
<span><?php echo $bcity; ?> </span>
</div>
<h4><?php echo $btitle; ?> </h4>
<p><?php echo $bdesc; echo "<br>
condation:".$bstatus; ?> </p>
</div>
</div>
</li>
<?php
} //end of second if
} // end of while ?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
This image shows what I got (all the data in one row instead of 4 books per row !):
image slider code :
<div class="popular_causes_area section_padding">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="causes_active owl-carousel">
<div class="single_cause">
<div class="thumb">
<?php
if ($bpic == "" ) {
echo "<img src='img/default-image.png' height=450px'>";
} else {
echo "<img src='img/$bpic' placeholder='nooooo' height=450px alt=''>";
}
?>
</div>
<div class="causes_content">
<div class="balance d-flex justify-content-between align-items-center">
<span>Tell:<?php echo $bnumber; ?> </span>
<span><?php echo $bcity; ?> </span>
</div>
<h4><?php echo $btitle; ?> </h4>
<p><?php echo $bdesc; echo "<br> condation:".$bstatus; ?> </p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Connecting images from SQL

Every time I try and load the page below the images do not show. I have the image names in an SQL database and also have the image folder in the same path as my index.php.
<div class="container-fluid">
<div class="col-md-12">
<div class="row">
<div class="col-md-6">
<h2 class="text-center">Products</h2>
<?php
$query = "SELECT * FROM product";
$result = mysqli_query($connect,$query);
while ($row = mysqli_fetch_array($result)) {?>
<form method="get" action="index.php?id=<?= $row['id'] ?>">
<img src="img/<?= $row['image'] ?>" style='height: 150px;'>
<h2><?= $row['name']; ?></h2>
<h2><?= $row['price']; ?></h2>
</form>
<?php }
?>
</div>
<div class="col-md-6">
<h2 class="text-center">Shopping Cart</h2>
</div>
</div>
</div>
</div>
</body>
</html>
I tried this code on my computer and the image appears perfectly.
Perhaps, you forgot to place a connection query.
<div class="container-fluid">
<div class="col-md-12">
<div class="row">
<div class="col-md-6">
<h2 class="text-center">Products</h2>
<?php
$connect = mysqli_connect('localhost','root','','test');
$query = "SELECT * FROM product";
$result = mysqli_query($connect,$query);
while ($row = mysqli_fetch_array($result)) {?>
<form method="get" action="index.php?id=<?= $row['id'] ?>">
<img src="img/<?= $row['image'] ?>" style='height: 150px;'>
<h2><?= $row['name']; ?></h2>
<h2><?= $row['price']; ?></h2>
</form>
<?php }
?>
</div>
<div class="col-md-6">
<h2 class="text-center">Shopping Cart</h2>
</div>
</div>
</div>
</div>

How to print out mySQL database into a div table?

Grades table is this:
username assignment weight mark
a a1 10% 50%
b a1 10% 60%
How would I print this out using php/html?
<div class="a">
<div class="divTableHeading">
<div class="divTableRow">
<div class="divTableHead">Username</div>
<div class="divTableHead">assignment</div>
<div class="divTableHead">weight</div>
<div class="divTableHead">mark</div>
</div>
</div>
<div class="divTableBody">
<?php
include("config.php");
$sql = "SELECT username, assignment, weight, mark FROM grades";
$result = mysqli_query($db,$sql);
while($row = $result->fetch_assoc()) {
?>
<div class="divTableRow">
<div class="divTableCell">$row['username']</div>
<div class="divTableCell">$row['assignment']</div>
<div class="divTableCell">$row['weight']</div>
<div class="divTableCell">$row['mark']</div>
</div>
</div>
</div>
$db is the connected database that is from config.php. How would I keep looping through and output the grades table?
accidental edit
You're missing to echo your record values.
From just $row['username'] changed to <?php echo $row['username']; ?>
And you missed } to close your while loop. Closed it as well with - <?php } ?>
Updated code:
<div class="divTable blueTable">
<div class="divTableHeading">
<div class="divTableRow">
<div class="divTableHead">Username</div>
<div class="divTableHead">assignment</div>
<div class="divTableHead">weight</div>
<div class="divTableHead">mark</div>
</div>
</div>
<div class="divTableBody">
<?php
include("config.php");
$sql = "SELECT username, assignment, weight, mark FROM grades";
$result = mysqli_query($db,$sql);
while($row = $result->fetch_assoc()) {
?>
<div class="divTableRow">
<div class="divTableCell"><?php echo $row['username']; ?></div>
<div class="divTableCell"><?php echo $row['assignment']; ?>/div>
<div class="divTableCell"><?php echo $row['weight']; ?></div>
<div class="divTableCell"><?php echo $row['mark']; ?></div>
</div>
<?php } ?>
</div>
</div>
Don't forget to output your values
<?php echo $row['username']; ?>

Horizontal looping mysql inside div tag

Can someone help me to make content looping similiar with this website?
I tried to use while() construct and it was looping vertically. It appears without using table and I assume that this page is using thumbnail.
What I really need is the items will loop every 3 items and this is the code that I wrote and appears vertically.
<div class="container">
<?php
include "config/database.php";
$sql = "SELECT * FROM anidata";
$query = mysql_query($sql);
if ($query > 0) {
?>
<div class="col-sm-6 col-md-4" style="float: left;">
<?php
while($row = mysql_fetch_array($query)){
$image = $row['image'];
$title = $row['title'];
$genre = $row['genre'];
$start = $row['start'];
$schedule = $row['schedule'];
$description = $row['description'];
?>
<div class="row">
<div class="thumbnail" >
<div>
<img src="admin/<?php echo $row['image']; ?>" width="194" height="272">
</div>
<div class="caption">
<span id="teks" style="font-size:18px;"><?php echo $title; ?></span>
<div class="line-title">
</div>
<div class="description">
<span style="font-size:12px;"><?php echo $description; ?></span>
</div>
<div class="genre">
<span><?php echo $genre; ?></span>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
Try this. If .thumbnail already have float:left; in your css you can remove the style attr.
<div class="container">
<?php
include "config/database.php";
$sql = "SELECT * FROM anidata";
$query = mysql_query($sql);
if ($query > 0) {
?>
<div class="col-sm-6 col-md-4" style="float: left;">
<div class="row">
<?php
while($row = mysql_fetch_array($query)){
$image = $row['image'];
$title = $row['title'];
$genre = $row['genre'];
$start = $row['start'];
$schedule = $row['schedule'];
$description = $row['description'];
?>
<div class="thumbnail" style="float:left;">
<div>
<img src="admin/<?php echo $row['image']; ?>" width="194" height="272">
</div>
<div class="caption">
<span id="teks" style="font-size:18px;"><?php echo $title; ?></span>
<div class="line-title">
</div>
<div class="description">
<span style="font-size:12px;"><?php echo $description; ?></span>
</div>
<div class="genre">
<span><?php echo $genre; ?></span>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } ?>
</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