Adding Image to Carousel Slider - php

enter image description here
<div id="demo" class="carousel slide" data-ride="carousel">
<?php $count = count($veriler);?>
<ul class="carousel-indicators">
<?PHP
$i=0;
for ($i=0;$i<$count;$i++) { ?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>"></li>
<?php } ?>
</ul>
<div class="carousel-inner">
<?php
$j=0;
foreach ($veriler as $row) { ?>
<div class="item <?php if($j==0) { echo "active"; } ?>">
<div style="max-width:1100px; max-height:500px;">
<img src=" <?php echo $row["haberekle_konu"]; ?>" alt="Los Angeles">
</div>
<div class="carousel-caption">
<h3> <?php echo $row["haberekle_baslik"]; ?> </h3>
</div>
</div>
<?php $j++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
i want to add in Carousel Slider a few images.
i posted image and caption from admin panel and i saved to database. when i extracted data from the database, result that: See i added the image. No picture display.
enter image description here
<?php
$veriler = $db->query("SELECT * FROM haberlerekle",PDO::FETCH_ASSOC)->fetchAll();
?>
i think, that codes need.

The symbol the top left cornor(https://i.stack.imgur.com/7UgIN.jpg) indicates a "broken link".
This means, the path does not point on a File.
Or u maybe need a absolute/relativ path(HTML showing broken image)
Make sure the path of the image u try to paste in the src-attribute is realy there.
U can try it by pasting the content of
$row["haberekle_konu"]
behind the URL.
If the image not appear, the path ist not correct.

Eventually i found the codes i was looking for. i found youtube. The codes and youtube link below.
Youtube Link
slider.php
<?php
$veriler = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id DESC LIMIT 12",PDO::FETCH_ASSOC)->fetchAll();
/* $veriler = $db->query("SELECT * FROM haberlerekle ORDER BY haberekle_id DESC LIMIT 7"PDO::FETCH_ASSOC)->fetchAll(); */
?>
<div id="demo" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<?php
$i = 0;
foreach ($veriler as $row) {
$actives = '';
if($i == 0) {
$actives = 'active';
}
?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>" class="<?php echo $actives; ?>"></li>
<?php $i++; } ?>
</ul>
<div class="carousel-inner">
<?php
$i = 0;
foreach ($veriler as $row) {
$actives = '';
if($i == 0) {
$actives = 'active';
}
?>
<div class="carousel-item <?php echo $actives; ?>">
<img src="upload/images/<?php echo $row['haberekle_konu']; ?>" width="832" height="502">
<div class="carousel-caption">
<p><?php echo $row["haberekle_baslik"]; ?></p>
</div>
</div>
<?php $i++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
admin.php
<?php
if(isset($_POST['resimyukle'])) {
$yazi = $_POST['haberekle_baslik'];
$yukleklasor = "../../../upload/images";
$tmp_name = $_FILES['yukle_resim']['tmp_name'];
$name = $_FILES['yukle_resim']['name'];
$boyut = $_FILES['yukle_resim']['size'];
$tip = $_FILES['yukle_resim']['type'];
$uzanti = substr($name,-4,4);
$rasgelesayi1 = rand(10000,50000);
$rasgelesayi2 = rand(10000,50000);
$resimad = $rasgelesayi1.$rasgelesayi2.$uzanti;
//dosya var mı kontrol
if(strlen($name) == 0) {
echo "Bir Dosya Seçiniz";
exit();
}
//boyut kontrol
if($boyut > (1024*1024*3)) {
echo "Dosya Boyutu Çok Fazla";
exit();
}
//tip kontrol
if($tip != 'image/jpeg' && $tip != 'image/png' && $uzanti != '.jpg') {
echo "Yalnızca jpeg veya png formatında olabilir";
}
move_uploaded_file($tmp_name, "$yukleklasor/$resimad");
$resimsor = $db->prepare("INSERT INTO haberlerekle set haberekle_konu=:ad, haberekle_baslik=:baslik");
$resimyukle = $resimsor->execute(array('ad'=> $resimad, 'baslik'=> $yazi));
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="haberekle_baslik" size="100"></input><br><br>
<input type="file" name="yukle_resim" /><br>
<input type="submit" value="Yükle" name="resimyukle" />
</form>
Thank you for your help.

Related

How to set first menu active in mega menu?

I am trying to create a hoverable mega menu, all works fine except the active one.
I checked in source codes and active class is added, but it doesn't show up the content until mouseenter on it.
see image please :
And this is when I go on it with mouse, it show up with no problem.
I gues I need to set main (FINANCE is main menu in pic) menu active, but dont know how to pass it to submenu.
Here is my full code :
$stmt_menu = $pdo->prepare("SELECT * FROM categories WHERE parentId = ? LIMIT 5");
$stmt_menu->execute([0]);
if ($stmt_menu->rowCount() > 0) {
$query = $stmt_menu->fetchAll();
foreach ($query as $row) {
if ($row['cat_type'] == 'mega') {
?>
<li class="dropdown megamenu-fw mega-li-<?php echo $row['catId']; ?>">
<?php echo $row['catName']; ?><span class="caret"></span>
<ul class="dropdown-menu megamenu-content dropdown-top" role="menu" aria-expanded="true" data-mega-ul="<?php echo $row['catId']; ?>">
<li>
<?php
$stmt_menu = $pdo->prepare("SELECT * FROM categories WHERE parentId = ? LIMIT 5");
$stmt_menu->execute([$row['catId']]);
if ($stmt_menu->rowCount() > 0) {
$subquery = $stmt_menu->fetchAll();
?>
<div class="sub-menu-left">
<ul class="nav-sub-categories">
<?php
$i = 0;
foreach ($subquery as $subq) {
$actives = '';
if($i == 0){
$actives = ' active';
}
?>
<li data-category-filter="<?php echo $subq['cat_seo_url']; ?>-<?php echo $subq['catId']; ?>" class="li-sub-category<?php echo $actives; ?>"><?php echo $subq['catName']; ?></li>
<?php
$i++;
}
?>
</ul>
</div>
<div class="sub-menu-right">
<?php
$i = 0;
foreach ($subquery as $subcats) {
$actives = '';
if($i == 0){
$actives = ' active';
}
?>
<div class="sub-menu-inner filter-<?php echo $subcats['cat_seo_url']; ?>-<?php echo $subcats['catId']; ?><?php echo $actives; ?>">
<div class="row row-menu-right">
<div class="col-sm-3 menu-post-item">
<div class="post-item-image">
<a href="is-allowance-instantly-strangers-applauded">
<img src="assets/img/img_bg_md.png" data-src="uploads/images/202203/image_380x226_624239afd7295.jpg" alt="Is allowance instantly strangers applauded" class="lazyload img-responsive img-post" width="1" height="1"/>
</a>
</div>
<h3 class="title"><?php echo $subcats['cat_seo_url']; ?> Is allowance instantly strangers applauded</h3>
<p class="post-meta">
admin
<span>Mar 28, 2022</span>
<span><i class="icon-comment"></i>2</span>
<span class="m-r-0"><i class="icon-eye"></i>894</span>
</p>
</div>
</div>
</div>
<?php
$i++;
}
?>
</div>
<?php
}
?>
</li>
</ul>
</li>
<?php
} elseif ($row['cat_type'] == 'dropdown') {
echo ' <li class="nav-item"><a class="nav-link" href="' . $row["cat_seo_url"] . '">test</a></li>';
} else {
echo ' <li class="nav-item"><a class="nav-link" href="' . $row["cat_seo_url"] . '">' . $row["catName"] . '</a></li>';
}
}
}

Loading images to Bootstrap carousel from a MySQL database using PDO (fetchall problem)

I'm using PDO to insert images from a database to a Bootstrap carousel. By that I mean ( loading The image path ), but the problem is when I use fetchall(); or fetch I get all rows value like this:
require_once '..\Config.php';
$dbCon = "mysql:host=$host;dbname=$db_name";
$conn = new PDO($dbCon, $username, $password);
$getquery = $conn->prepare('SELECT (imageurl) FROM special');
$getquery->execute();
$result = $getquery->fetchall();
echo $result['imageurl'];
The output is: Efexor.jpg path upload/17.jpg upload/17.jpg upload/19.jpg upload/18.jpg upload/18.jpg* that is all rows from imageurl column, so when I loop foreach ($result) to load images from database to a Bootstrap carousel. It dose't work
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
<?
$i = 0;
foreach($result as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<li data-target="#demo" data-slide-to="<?= $i; ?>" class="<?= $actives;?>"></li>
<? $i++ ; }?>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<?
$i = 0;
foreach($result as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<div class="carousel-item <?= $actives;?>">
<img src="<?= $row['imageurl']?>">
</div>
<? echo $row['imageurl'];?>
<? $i++; }?>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
Try like this:
<!-- The slideshow -->
<div class="carousel-inner">
<?
$i = 0;
$full_url = 'YOUR URL AND PATH TO IMAGE FOLDER HERE';
foreach($result as $row){
$actives = '';
if($i == 0){
$actives ='active';
}
?>
<div class="carousel-item <?= $actives;?>">
<img src="<?= $full_url . $row['imageurl']?>">
</div>
<? echo $full_url . $row['imageurl'];?>
<? $i++; }?>
</div>

How to fetch comments from mysql database without destroying my html tags

I want to give a little style for my comment section, here is the code without any css, but i want to give it some style
<div id="comments">
<?php
$sql = "SELECT * FROM comments ORDER BY id LIMIT 2";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>";
echo $row['author'];
echo "<br>";
echo $row['message'];
echo "<br>";
echo $row['time'];
echo "</p>";
}
} else {
echo "there are no comments!";
}
?>
</div>
<button>More comments</button>
and down here is my html section of which i want to appear while handling my php comments where USER, COMMENT and TIME are are stored in my database, here is the html, how can i echo the above variables into the below html tags ?
<div class="media response-info">
<div class="media-left response-text-left">
<a href="#">
<img class="media-object" src="images/c1.jpg" alt="">
</a>
<h5>USER</h5>
</div>
<div class="media-body response-text-right">
<p>COMMENT</p>
<ul>
<li>TIME</li>
<li>Reply</li>
</ul>
</div>
</div>
You can do like this:
<div id="comments">
<?php
$sql = "SELECT * FROM comments ORDER BY id LIMIT 2";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) { ?>
<div class="media response-info">
<div class="media-left response-text-left">
<a href="#">
<img class="media-object" src="images/c1.jpg" alt="">
</a>
<h5><?php echo $row['author']; ?></h5>
</div>
<div class="media-body response-text-right">
<p><?php echo $row['message']; ?></p>
<ul>
<li><?php echo $row['time']; ?> </li>
<li>Reply</li>
</ul>
</div>
</div>
<?php }
} else {
echo "there are no comments!";
}
?>
</div>
hope it will help you.

Show random product on homepage through phtml

I have a block being displayed on my homepage which shows a product, whose id we specify. The code on homepage (static block) looks like this:
{{block type="core/template" product_id="2559" template="catalog/product/one_product.phtml"}}
The one_product.phtml file contains this code:
<?php
$productId = $this->getProduct_id();
$product = Mage::getModel('catalog/product')->load($productId); //load product
?>
<div class="product">
<a href="<?php echo $product->getProductUrl() ?>" >
<img class="product-img" src="<?php echo $this->helper('catalog/image')->init($product, 'image'); ?>"alt="<?php echo $this->htmlEscape($product->getName()) ?>" />
</a>
</div>
<div class="product-detail">
<P><?php // echo $this->htmlEscape($product->getName()) ?>
<?php $prod_name = $this->htmlEscape($product->getName()); ?>
<?php
$count_str = strlen($prod_name);
if ($count_str < 40) {
echo $prod_name;
} else {
$offset = 0;
$length = 41;
$prod_name = html_entity_decode($prod_name);
echo htmlentities(mb_substr($prod_name,0,$length,'utf-8')). "...";;
}
?>
</P>
<!--?php $price = $product->getPrice() ; ?-->
<?php $_product = Mage::getModel('catalog/product')->load($product->getId());
$productBlock = $this->getLayout()->createBlock('catalog/product_price');
?>
<span>
<?php echo $productBlock->getPriceHtml($_product); ?>
<?php $tier_price = end($_product->getTierPrice());
if($tier_price !='0'){ ?>
<span>As Low As:</span>
<?php
echo " ₹ ".number_format( $tier_price['price']);
} ?>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart"
onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($product); ?>')">
</span>
</div>
So basically I want to show random products out of the ones I specify separated by commas. For eg: I specify in the static block product_id="2559,2661,2857,9293" and it should show any one of those 4 products randomly.
What is the way to do that?
Also any way to make it pull products from SKU also? Since we remember all the SKUs but we have to check each product ID everytime we change the product here.
Please excuse me if the question is too basic, I'm not a developer.
You can see it in action at www.giftzila.com
Thanks!
Create a new file called random-product.phtml at app/design/frontend/default/Your_Theme/template/catalog/random-product.phtml then add the following code in that file
<?php
$chosen_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$_productCollection = $this->getLoadedProductCollection();
$number_of_products = $this->getNumProducts();
if (sizeof($_productCollection) < $number_of_products) {
$number_of_products = sizeof($_productCollection);
}
$displayed_products = array();
foreach ($_productCollection as $_product) {
$displayed_products[] = $_product;
}
$random_products = array();
if (sizeof($_productCollection) > 1) {
$random_products = array_rand($displayed_products, $number_of_products);
} else {
$random_products = array('0');
}
?>
<?php if(!$_productCollection->getSize()):?>
<div class="note-msg">
<?=$this->__('There are no products matching the selection.')?>
</div>
<?php else:?>
<div class="main-binder">
<div class="cms-box">
<div class="category-title">
<h2>Random Products</h2>
</div>
<div class="category-products">
<table id="products-grid-table" class="products-grid">
<?php
$k=0;
for ($i=0; $i < $number_of_products; $i++): ?>
<?php if ($k == 0) { ?>
<tr class="first odd">
<?php } if($k==3) { $k=0; ?>
</tr><tr class="first odd even">
<?php } ?>
<td id="td_<?php echo ($k+1); ?>" <?php if($k==3){ ?>class="last"<? } ?> >
<div class="cms-box">
<div id="cont_<?php echo ($k+1); ?>">
<div class="product-name-block">
<?php
$pname=$this->htmlEscape($displayed_products[$random_products[$i]]->getName());
?>
<h3 class="product-name">
<a href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>" title="<?php echo $pname; ?>">
<?php if(strlen($pname) > 28) {echo substr($pname,0,25)."...";}else {echo $pname;}?>
</a></h3>
</div>
<div class="image-box">
<a class="product-image" href="<?php echo $displayed_products[$random_products[$i]]->getProductUrl()?>"> <img src="<?php echo $this->helper('catalog/image')->init($displayed_products[$random_products[$i]], 'small_image')->resize(140);?>" alt="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>" title="<?php echo $this->htmlEscape($displayed_products[$random_products[$i]]->getName())?>"/> </a>
</div>
<div class="cms-price-box" style=" text-align:center;">
<span class="regular-price" id="product-price-37">
<span class="price" ><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol().$displayed_products[$random_products[$i]]->getPrice(); ?></span>
</span>
</div>
<div class="button-row" style="text-align:center;">
<button onclick="setLocation('<?php echo $displayed_products[$random_products[$i]]->getProductUrl();?>')" class="button" type="button"><span><span><span>Details</span></span></span></button>
<button onclick="setLocation('<?php echo $this->getUrl('')."/checkout/cart/add?product=".$displayed_products[$random_products[$i]]->getId()."&qty=1" ?>')" class="button"><span><?php echo $this->__('Add to Cart') ?></span></button>
</div>
</div>
</div></td>
<?php $k++; ?>
<?php endfor;?>
</tr>
</table>
</div>
</div>
</div>
<?php endif;?>
Now call block in your cms home page by adding following code:-
{{block type="catalog/product_list" category_id="3" num_products="8" template="catalog/random-product.phtml"}}

upload and show(select) video in php

I make a form through i can upload images and videos, the file's are stor in some folder and the path is stored in mysql table, now when i select the image file then i would show properly, my image selection code is...
$smt=$conn->prepare('SELECT * FROM post');
$smt->execute();
<?php while($gdata=$smt->fetch(PDO::FETCH_OBJ)):?>
<img src="posts/<?php echo $gdata->Post_Path; ?>" alt="image" class="post-image"/>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category;?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date;?></li>
</ul>
<h4 class="media-heading h4"><?php echo $gdata->Title;?></h4>
<p class="post-text"><?php echo $gdata->Post;?></p>
</div>
</div>
<?php endwhile;?>
now the problem is that through the above way i can access the video file but it can't be shown? How can i check that the file is image or video?
In my database the path will store like, example.jpg/mypic.png, test.mp4, how can i check the last extension of file?
my updated code is...
<?php
include 'conn.php';
$smt=$conn->prepare('SELECT * FROM post');
$smt->execute();
$row=$smt->fetch(PDO::FETCH_OBJ);
$row->Post_Path;
$ext=pathinfo($row,PATHINFO_EXTENSION);
?>
<?php if($ext=='mp4')
{?>
<?php while($gdata=$smt->fetch(PDO::FETCH_OBJ)):?>
<a href="#" class="media-left col-md-4 clearfix"><video class="post-image" controls>
<source src="posts/<?php echo $gdata->$ext;?>" type="video/mp4">
</video></a>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category;?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date;?></li>
</ul>
<h4 class="media-heading h4"><?php echo $gdata->Title;?></h4>
<p class="post-text"><?php echo $gdata->Post;?></p>
</div>
</div>
<?php endwhile;
}
elseif($ext=='jpg||jpeg||png')
{
?>
<?php while ($gdata = $smt->fetch(PDO::FETCH_OBJ)): ?>
<a href="#" class="media-left col-md-4 clearfix"><img src="posts/<?php echo $gdata->Post_Path; ?>" alt="image"
class="post-image"/></a>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category; ?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date; ?></li>
</ul>
<a href="post-description.php?id=<?php echo $gdata->Id ?>"><h4
class="media-heading h4"><?php echo $gdata->Title; ?></h4></a>
<p class="post-text"><?php echo $gdata->Post; ?></p>
</div>
</div>
<?php endwhile;
}?>
I am not able to show video in my index page, how to show it, however i am able to show the image..
Any help would be appreciated.
$info = new SplFileInfo('testing.jpg');
var_dump($info->getExtension());
Reference
Before someone comes in and says this requires extra installations
This extension is available and compiled by default in PHP 5.0.0.
Reference
Check this one. which may helps you..
For PHP < 5.3 use mime_content_type()
For PHP >= 5.3 use finfo_fopen()
$smt=$conn->prepare('SELECT * FROM post');
$smt->execute();
<?php while($gdata=$smt->fetch(PDO::FETCH_OBJ)):
$mime = mime_content_type($gdata->Post_Path);
if(strstr($mime, "video/")){
// this code for video
$file='';
}else if(strstr($mime, "image/")){
// this code for image
$file='<img src="posts/'.$gdata->Post_Path.'" alt="image" class="post-image"/>';
}
?>
<?php echo $file?>
<div class="media-body col-md-8 post-image-space pull-left">
<div class="post-overview">
<ul>
<li class="post-category"><?php echo $gdata->Category;?></li>
<li class="post-timestemp">Post on <?php echo $gdata->Post_Date;?></li>
</ul>
<h4 class="media-heading h4"><?php echo $gdata->Title;?></h4>
<p class="post-text"><?php echo $gdata->Post;?></p>
</div>
</div>
<?php endwhile;?>
mime_content_type Should work for most file extentions.
Try this:
$fileInfo = pathinfo($gdata->Post_Path);
if($fileInfo['extension'] == 'png')
{
echo "It's an PNG";
}
elseif($fileInfo['extension'] == 'mp4')
{
echo "It's an MP4";
}
$file_parts = pathinfo($filename);
switch($file_parts['extension'])
{
case "jpg":
break;
case "exe":
break;
case "": // Handle file extension for files ending in '.'
case NULL: // Handle no file extension
break;
}
may be it's help you.try it

Categories