When running this on the page it takes a long time for the page to load and halts then in one shot displays everything is there any way i can fast?
things i've tried is saving that portion into a .html and displaying it from there still does not make a difference, also tried using lozad.js to load the images still does the same thing
<div class='person-videos-text'>
<div class="row">
<?php
while($row = mysqli_fetch_assoc($recentTreningVideos))
{
$TrendImageURL = $row['youtubethumbnail'];
$TrendSongName = $row['musicvideotitle'];
$TrendCleanSongname = $row['songname'];
$name = $row['youtubethumbnail'];
$rippedUrl = explode("/",$name);
//print_r($rippedUrl);
$hostt = $rippedUrl[0];
$hostUrl = $rippedUrl[2];
$imageNameVi = $rippedUrl[3];
$imageNameUrl = $rippedUrl[4];
$imageType = $rippedUrl[5];
?>
<div class="column trending">
<div class="card">
<a href="viewactors.php?songname=<?php echo $TrendCleanSongname; ?>">
<img class="trending-image-size" src="cached/<?php echo $imageNameUrl;?>/<?php echo $imageType; ?>" alt="John">
<div class="person-container">
<!--<h2>John Doe</h2>-->
<p class="title trending-title"><?php echo $TrendSongName; ?></p>
<!--<p>Some text that describes me lorem ipsum ipsum lorem.</p>
<p>example#example.com</p>
<p><button class="button">Contact</button></p>-->
</div>
</a>
</div>
</div>
<?php } ?>
</div>
</div>
Related
I have a page that runs off a local webserver that is uses SQLite as its database. As its used local I am not worried about listing all results on one page as they load super fast. I am having an issue with it though as after 500 results are displayed from SQLite3 the formatting goes all wonky and starts stacking them on top of each other. Everything before that is fine. Its written in php. Info was entered into the database using htmlspecialchars so I dont believe that is the issue. The code that builds each record in the loop is
$list = '';
while($row = $results->fetchArray()) {
$id = $row["id"];
$MovieTitle = $row["MovieTitle"];
$MovieYear = $row["MovieDate"];
$MovieRes = $row["MovieRes"];
$FileName = $row["FileName"];
$Summary = $row["Summary"];
$Genres = $row["Genres"];
$PictureLocation = $row["PictureLocation"];
$Rating = $row["Rating"];
$ReleaseDate = $row["ReleaseDate"];
$list .= '<div class="box">
<div class="movie">
<div class="movie-image"><span class="play"><span class="name">'.$MovieTitle.'</span></span><img src="'.$ThumbnailPic.'" alt=""></div>
<div class="rating">
<p>RATING: '.$Rating.'</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span></div>
</div>';
}
and i just echo them them in the html as such
<html>
<body>
<div id="main">
<br>
<?php echo $list; ?>
</div>
</body>
</html>
Your HTML is wrong, you did not close <div class="box"> and <span class="play"> tags properly.
Correct HTML is:
<div class="box">
<div class="movie">
<div class="movie-image">
<span class="play">
<a href="movielist.php?movie='.$FileName.'">
<span class="name">'.$MovieTitle.'</span>
<img src="'.$ThumbnailPic.'" alt="">
</a>
</span>
</div>
<div class="rating">
<p>
RATING: '.$Rating.'
</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span>
</div>
</div>
</div>
Aso, you can have some tags or quotes in your database records. So you have to use escaping your variables before output http://php.net/manual/en/function.htmlspecialchars.php
Something like this:
$list = '';
while($row = $results->fetchArray()) {
$id = htmlspecialchars($row["id"]);
$MovieTitle = htmlspecialchars($row["MovieTitle"]);
$MovieYear = htmlspecialchars($row["MovieDate"]);
$MovieRes = htmlspecialchars($row["MovieRes"]);
$FileName = htmlspecialchars($row["FileName"]);
$Summary = htmlspecialchars($row["Summary"]);
$Genres = htmlspecialchars($row["Genres"]);
$PictureLocation = htmlspecialchars($row["PictureLocation"]);
$Rating = htmlspecialchars($row["Rating"]);
$ReleaseDate = htmlspecialchars($row["ReleaseDate"]);
$list .= '<div class="box">
<div class="movie">
<div class="movie-image"><span class="play"><span class="name">'.$MovieTitle.'</span></span><img src="'.$ThumbnailPic.'" alt=""></div>
<div class="rating">
<p>RATING: '.$Rating.'</p>
<div class="stars">
<div class="'.$StarGraphic.'"></div>
</div>
<span class="comments"></span></div>
</div>';
}
This is some Bootstrap HTML where I need to create multiple blocks like a table but it just grabs the first item in the DB and prints 50 of them. I'm having trouble figuring out how to mingle the php code and html code so it works correctly.
<section id="latest-news" class="latest-news-section">
<div class="container">
<?php
include_once ('mysql.inc.php');
$ix = $_POST['i'];
$sql = "SELECT * from deposits WHERE d_userid = '$ix' ORDER BY _productionid ASC";
$query = #mysql_query($sql);
$outcome = #mysql_fetch_array($query);
foreach ($outcome as $result1){
?>
This part comes out nicely formatted, but the only data is the first item in the DB, and there are 50 copies made
<div class="col-md-4 col-sm-4">
<div class="latest-post">
<img src="assets/images/<?php echo $outcome['d_picture'] ?>" class="img-responsive" alt="">
<h4>Your ST1 <?php echo $outcome['d_firstname'] ?></h4>
<p>Prod ID <?php echo $outcome['d_productionid'] ?></p>
<p>Color: <?php echo $outcome['d_color'] ?><br />
Equip: <?php echo $outcome['d_equip'] ?><br />
Custom: <?php echo $outcome['d_custom'] ?></p>
<a class="btn btn-primary">View More</a>
</div>
</div>
<?
}
#mysql_close;
?>
</div>
</section>
You should use $result1 and not $outcome
ex: $result1['d_picture']
I'm trying to configure my database data that is being pulled with php to look like my homepage.
I can't figure out what I need to do.
This is for a project for school, and I have very limited knowledge on php.
Here is my php script.
<?php
include('mysql_connect.php');
$dbh = con();
foreach($dbh->query("SELECT * FROM `Product` WHERE `ProductType` = 'memory' ",PDO::FETCH_ASSOC) as $row){
$Pname = $row['ProductName'];
$description = $row['description'];
$price = $row['ProductPrice'];
$ID = $row['ProductID'];
echo <div class="row">;
echo <div class="col-sm-4 col-lg-4 col-md-4">;
echo <div class="thumbnail">;
<img src="/var/www/html/Pictures/gigb75m_home.jpg" alt="">
echo "<div class="caption">";
echo "<h4 class="pull-right">$price</h4>";
echo "<h4>$Pname</h4>";
echo "<p>$description</p>";
echo "<p>$ID</p>";
}
?>
</div>
</div>
</div>
Here is my index that has my desired results.
<div class="row">
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="/var/www/html/Pictures/gigb75m_home.jpg" alt="">
<div class="caption">
<h4 class="pull-right">$74.99</h4>
<h4>GIGABYTE GA-B75M
</h4>
<p>Micro ATX, LGA 1155, Intel B75 Express Chipset, 2200MHz DDR3 (O.C.), SATA III (6Gb/s), 7.1-CH Audio, Gigabit LAN, USB 3.0 - GA-B75M-D3H</p>
</div>
</div>
</div>
Picture of homepage: http://imgur.com/g72Wrxk
Any help/guidance is greatly appreciated, this is driving me crazy.
Use '.' for string concatinations.
For example:
echo '<h4 class="pull-right">' . $price . '</h4>';
You have to use single quote to echo content in your PHP script like this for instead :
echo '<div class="row">';
The single quotes are used to explain that it's a string to show. You have to do the same for your other echo part.
Or you can escape the HTML part from the PHP and replace by vars inside it like this :
<?php
include('mysql_connect.php');
$dbh = con();
echo '<div class="row">';
foreach($dbh->query("SELECT * FROM `Product` WHERE `ProductType` = 'memory' ",PDO::FETCH_ASSOC) as $row){
$Pname = $row['ProductName'];
$description = $row['description'];
$price = $row['ProductPrice'];
$ID = $row['ProductID'];
?>
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="/var/www/html/Pictures/gigb75m_home.jpg" alt="">
<div class="caption">
<h4 class="pull-right"><?php echo $price; ?></h4>
<h4><?php echo $Pname; ?></h4>
<p>$description</p>
<p>$ID</p>
</div>
</div>
</div>
<?php
}
?>
</div>
Also you have to be careful about the row system of bootstrap to echo col-md-4 inside a row, you can add 3 items like this per row. So you have to close and reopen a row each time you fetch 3 elements to get a correct HTML structure.
You didn't supplied any information about your database, yet the first problem that's visible is your echo's
To output HTML through PHP you have to output pure strings.
An example for that would be ""
In PHP when you want to connect different kinds of inputs like variables and "" or '' etc you connect them with a dot.
For example:
$string = ' hello3';
echo "Hello 1 ".' hello2 '.$string;
The outcome will be:
Hello 1 hello2 hello3
I hope you got it the hang of it.
I am creating a blog in PHP (trying to keep it close to OOP) and am struggling with getting pagination to work on the page that displays all posts.
The code for the blog.php in question is
<?php
require_once("includes/init.php");
$pagetitle = "Blog";
//include header.
require_once("includes/template/header.php");
// initialise script
$blog = new Blog($db);
$parsedown = new Parsedown();
// load blog posts
$posts = $blog->get_posts();
?>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Blog Home</h1>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<?php foreach ($posts as $post) { ?>
<h1><?php echo $post['title']; ?>
</h1>
<p class="lead">by <?php echo $post['author']; ?>
</p>
<hr>
<p><i class="fa fa-clock-o"></i> Posted on <?php echo date("d/m/Y", strtotime($post['date'])); ?> At <?php echo date("H:i", strtotime($post['date'])); ?> in <?php
$categories = $blog->get_categories($post['id']);
$links = array();
foreach ($categories as $category) {
$links[] = "<a href='blog-categories.php?id=".$category['category_slug']. "'>".$category['category_name']."</a>";
}
echo implode(", ", $links); ?></p>
<hr>
<p><?php $content = $parsedown->parse($post['content']); echo substr($content,0,445) ; ?></p>
<a class="btn btn-primary" href="<?php echo $post['slug']; ?>">Read More <i class="fa fa-angle-right"></i></a>
<a class="btn btn-primary" href="<?php echo $post['slug']; ?>#disqus_thread"><i class="fa fa-angle-right"></i></a>
<hr>
<?php }
?>
</div>
What can I add either to the Blog class or put in a new class to allow blog.php to only show the first 5 results and then give a 'next' link to view the next set of 5? I'm not worried about displaying the total number of pages.
As the class is very large, it can be viewed at http://pastebin.com/qN5ii2Ta.
You are currently using a method get_posts(). You could redefine this method to accept a starting point to begin gathering posts from. With this starting point defined you can LIMIT how many posts are returned in your SQL query.
I'm doing a website where I want to show products from a database, and when clicking a product it opens a div with more detail info (without refreshing page or going to another).
The product gallery looks like this:
<div class="item_galery">
<?php
$i=0;
while($info = mysql_fetch_array( $data )){
$titulo = $info['titulo'];
$descr_corta = $info['descr_corta'];
$img_galeria = $info['img_galeria'];
$img_detalle = $info['img_detalle'];
$sub_img1 = $info['sub_img1'];
$sub_img2 = $info['sub_img2'];
$sub_img3 = $info['sub_img3'];
$acabado = $info['acabado'];
$aux_tamaños = $info['medidas'];
$tamaños = explode(" ", $aux_tamaños);
//echo $aux_tamaños.' '.sizeof($tamaños);
$patron_tornillos = $info['patron_tornillos'];
$coleccion = $info['coleccion'];
?>
<div class="item">
<ul><li onclick="mostra_detall(<?php echo $i;?>);"><img alt="" src="<?php echo 'images/llantas/'.$img_galeria; ?>"/></li></ul>
<ul><li class="descr"><span><?php echo $titulo; ?></span></br><?php echo $acabado; ?></li></ul>
</div>
<?php
$i++;
}
?>
in the class item, the first li has a js call function wihic shoud open the detail info. This info looks like:
<div id="detalle" class="llanta_detalle">
<img class="foto_gran" src="<?php echo 'images/llantas/'.$img_detalle; ?>">
<div class="info">
<div class="cerrar"><ul onclick="tanca_detall(<?php echo $i;?>);"><li><img src="images/llantas/icono_cerrar.jpg"></li><li>CERRAR</li></ul><div class="clear"></div></div>
<div class="detalle_titol">
<ul><li id="titol_llanta" class="titol"><?php echo $titulo; ?></li></ul>
<ul><li id="coleccion_llanta" class="coleccion"><?php echo $coleccion; ?></li></ul>
</div>
<div class="clear"></div>
<div class="detalle">
<ul><li class="requadre">ACABADO</li></ul>
<ul><li id="acabado_llanta" class="acabado"><?php echo $acabado; ?></li></ul>
<ul><li class="requadre">PATRON DE TORNILLOS</li></ul>
<ul><li id="tornillos_llanta" class="tornillos"><?php echo $patron_tornillos; ?></li></ul>
</div>
<div class="clear"></div>
<div class="subimagenes"><ul>
<li><a id="fancyBox" href="<?php echo 'images/llantas/'.$sub_img1; ?>"><img src="<?php echo 'images/llantas/'.$sub_img1; ?>"></a></li>
<li><a id="fancyBox" href="<?php echo 'images/llantas/'.$sub_img2; ?>"><img src="<?php echo 'images/llantas/'.$sub_img2; ?>"></a></li>
<li><a id="fancyBox" href="<?php echo 'images/llantas/'.$sub_img3; ?>"><img src="<?php echo 'images/llantas/'.$sub_img3; ?>"></a></li>
</ul></div>
</div>
<div class="clear"></div>
</div>
my problem is that when the div with detail info is open, I need the specific info from the query of that info, so I would need to do a query or somthing again and do it without refreshing the page. How could I do this?
Thanks and sorry for my english
I think that you should use Jquery for this. Here is a link. I gotta go to sleep now, but if you don`t have it done by tomorrow, I will help you! Hope the jquery link helps you though!