echo inside div inside echo [duplicate] - php

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>
";
}

Related

Bootstrap card element stretching

So the problem is that the cards are really stretching and I have tried everything to fix it and still haven't achieved the fix. Any way to fix this since I'm out of the clues? And what is the problem and where?
My container that holds cards
<div class="container mt-5">
<div class="row align-items-center">
<div class="col-sm-12 mx-auto">
<div class="card-group">
<?php
$companies = new Companies();
$companies->showAllCompanies();
?>
</div>
</div>
</div>
</div>
My PHP showAllCompanies code
public function showAllCompanies(){
$datas = $this->getAllCompanies();
foreach ($datas as $data){
$name = $data['name'];
$orgnr = $data['organization_number'];
$notes = empty($data['notes']) ? "No notes" : $data['notes'];
$id = $data['id'];
echo "
<div class='card me-2 d-block' style='width: 18rem;'>
<div class='card-body'>
<h4 class='card-title'>$name</h4>
<p class='card-text'><i class='bi bi-stickies'></i> $notes</p>
</div>
<ul class='list-group list-group-flush'>
<li class='list-group-item'>Stores Owned <span class='badge text-bg-primary'>XX</span></li>
<li class='list-group-item'>Organization Number <span
class='badge text-bg-primary'>$orgnr</span></li>
</ul>
<div class='card-body'>
<a href='#' class='btn btn-primary'>Edit</a>
<a href='#' class='btn btn-danger'>Delete</a>
</div>
</div>
";
}
return;
}
You're squeezing all your cards onto one row.
If you limit the amount of cards you display to 6 per row you can update your function to this:
public function showAllCompanies(){
$cardsPerRow = 6;
$i = 0;
$datas = $this->getAllCompanies();
foreach ($datas as $data){
$name = $data['name'];
$orgnr = $data['organization_number'];
$notes = empty($data['notes']) ? "No notes" : $data['notes'];
$id = $data['id'];
if($i == 0){
echo '<div class="row">';
}
echo "
<div class='card me-2 d-block' style='width: 18rem;'>
<div class='card-body'>
<h4 class='card-title'>$name</h4>
<p class='card-text'><i class='bi bi-stickies'></i> $notes</p>
</div>
<ul class='list-group list-group-flush'>
<li class='list-group-item'>Stores Owned <span class='badge text-bg-primary'>XX</span></li>
<li class='list-group-item'>Organization Number <span
class='badge text-bg-primary'>$orgnr</span></li>
</ul>
<div class='card-body'>
<a href='#' class='btn btn-primary'>Edit</a>
<a href='#' class='btn btn-danger'>Delete</a>
</div>
</div>
";
if(++$i >= $cardsPerRow){
echo '</div>';
$i = 0;
}
}
return;
}

PDF files are not shown in website but working fine in localhost

I want to read my "pdf files" in PHPMYSQL tables. So I found the script from some forums and it's work fine in "localhost using XAMPP".
But When I deploy to website, it's not showing pdf files and all information after that line are missing.
I dont know what is the problem. Kindly someone can help me please...
<div class="page-title">
<div class="container">
<div class="row">
<div class="col-md-12">
<ol class="breadcrumb">
<li>Home</li>
<li>Journals</li>
<li><?php echo $title; ?></a></li>
</ol>
</div>
</div>
</div>
</div>
<section class="block-wrapper">
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-12">
<div class="single-post">
<div class="post-title-area">
<a class="post-cat" href="<?php echo $post_cat_link; ?>"><?php echo $category; ?></a>
<h2 class="post-title">
<?php echo $title; ?>
</h2>
<div class="post-meta">
<span class="post-date"><i class="feather icon-clock"></i> <?php echo $post_date; ?></span>
<span class="post-comment"><i class="feather icon-eye"></i>
<span><?php echo $post_views; ?></span></span>
</div>
<div class="div1">
<?php echo "View PDF File for Journal Details" ?>
<?php
mysql_connect('localhost','adminjournal','adminjournalikat');
mysql_select_db('journal');
// mysql_connect('localhost','root','');
// mysql_select_db('journal');
$sql="SELECT pdf from tbl_blog_posts";
$query=mysqli_query($conn,$sql);
while ($info=mysqli_fetch_array($query)) {
?>
<embed type="application/pdf" src="pdf/<?php echo $info['pdf'] ; ?>" width="900" height="500">
<?php
}
?>
</div>
</div>
<div class="post-content-area">
<div class="entry-content">
<?php
if ($yt_vid == "") {
?>
<div class="post-media post-featured-image">
<img src="images/blog/<?php echo $media; ?>" class="img-fluid single_blog" alt="">
</div>
<?php
}else{
?>
<div class="post-media post-video">
<div class="embed-responsive">
<iframe src="https://www.youtube.com/embed/<?php echo $yt_vid; ?>"></iframe>
</div>
</div>
<?php
}
?>
<?php echo $cont?>
<br></br>
</div>
<div class="tags-area clearfix">
<div class="post-tags">
<span>Tags:</span>
<?php
$post_tags = explode(",",$tags);
foreach ($post_tags as $tag) {
if (WBCleanURL == "true") {
$st1 = preg_replace("/[^a-zA-Z]/", " ", $tag);
$st2 = preg_replace('/\s+/', ' ', $st1);
$tag_title = strtolower(str_replace(' ', '-', $st2));
$tag_link = "tags/$tag_title";
}else{
$tag_link = "pages/tags?key=$tag_title";
}
?><?php echo $tag; ?><?php
}
?>
</div>
</div>
<div class="share-items clearfix">
<ul class="post-social-icons unstyled">
<li class="facebook">
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $sharelink; ?>">
<i class="fa fa-facebook"></i> <span class="ts-social-title">Facebook</span></a>
</li>
<li class="twitter">
<a href="https://twitter.com/intent/tweet?url=<?php echo $sharelink; ?>">
<i class="fa fa-twitter"></i> <span class="ts-social-title">Twitter</span></a>
</li>
<li class="gplus">
<a href="mailto:info#example.com?&subject=&cc=&bcc=&body=<?php echo $sharelink; ?>">
<i class="fa fa-envelope"></i> <span class="ts-social-title">Email</span></a>
</li>
</ul>
</div>
</div>
</div>
thanks for your clue that this issue because of overlapping. Finally I found out the script problem... below is the right one...
Thanks a lot and Wish You All The Best
<?php echo $cont?>
<br></br>
<?php echo "PDF File Details for Journal" ?>
<br><h4><?php echo $title;?> </h4>

Getting Dropdown hidden id and get it using $_POST

I have this Dropdown made with bootstrap. I'm trying to take the id from the company the user has chosen to my $_POST method. In my table "empresas" I have two columns in it: 'id' and 'name';
This is my Dropdown code:
<ul class="nav nav-pills" role="tablist">
<li role="presentation" class="dropdown" style = "margin-left: auto; margin-right: auto">
</span>
<?php
require 'includes/dbh.inc.php';
$result = $conn->query("SELECT * from empresas") or die($conn->error);
?>
<ul class="dropdown-menu" id="menu1" aria-labelledby="drop4">
<?php
while ($row = $result->fetch_assoc()) : ?>
<li><a class="dropdown-item" href="#" name="idEmpresa" id = "idEmpresa" value = "<?php echo $row['id'] ?>" style="display:none;"><?php echo $row['id']; ?></a></li>
<li><a class="dropdown-item" href="#" value = "<?php echo $row['id'] ?>"><?php echo $row['nome']; ?> </a></li>
<?php endwhile; ?>
</ul>
</li>
</ul>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
<button type="submit" name="addDataDep" class="btn btn-primary" id="addbtn1">Adicionar</button>
</div>
</div>
</div>
</form>
</div>
</div>
And this is where i'll use the $_POST method:
if(isset($_POST['addDataDep'])) {
require 'dbh.inc.php';
$nomeDepartamento = $_POST['nomeDepartamento'];
$id = $_POST['idEmpresa'];
$_SESSION['message'] = "O departamento $idEmpresa foi adicionada com sucesso!";
}
require 'dbh.inc.php' already connects to my database.
When I try to $_POST it, it returns me this error: "Undefined index: idEmpresa".
Thank you for your help!

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>

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