After 500 results displayed from DB html/css loses formatting - php

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

Related

How to speed to page with lots of images load time

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>

Assign looped records to single variable using php

I need to get all looped records to single variable. I tried this but i got final records of loop. How do i get all records. Can you please solve this. Here i added my code,
$text = '';
$sql = mysql_query("SELECT * FROM table WHERE column_name = 'column_value'");
while($row = mysql_fetch_array($sql)){
$text = '<li><div class="row">
<div class="col-md-12 post">
<div class="row">
<div class="col-md-12">
<h5>
<strong>'.$row['field2'].'</strong></h4>
</div>
</div>
<div class="row post-content">
<div class="col-md-12">
<p style="margin-bottom:0px">
';
$text.= substr($row['field3'],0,150);
$text.= '...</p>
<a class="pull-right" href="'.$row['field2'].'.php">>> Read more</a>
</div>
</div>
</div>
</div></li>';
}
you are not concating your $text variable
$text = '';
while() { ...
$text .= '<li>...'; // you missed this dot
}
echo $text;

Take value from array and select it in mysql php

I have problem that I store in DB column (video_id) and the value of it like that store (1,3,4,7) the number mean the id of video in the Video table which store the video title and text and all information about the video but when I wrote code to select all video the result give me one video
<div class="panel-body">
<?
$qu="SELECT video_id FROM `training_questions` WHERE id=$questions_id AND category_id=$training_id";
$query_c= mysqli_query($con, $qu);
while ($row7 = mysqli_fetch_assoc($query_c)) {
$vedoes=$row['video_id'];
$pieces = explode(",", $vedoes);
}
for($i=0;$i<=count($pieces);$i++){
$query = "SELECT * FROM `video` WHERE id IN $pieces[$i] ";
$query_che= mysqli_query($con, $query);
while ($row2 = mysqli_fetch_assoc($query_che)) { ?>
<div class="col-lg-3 col-sm-6">
<div class="thumbnail">
<div class="video-container">
<div class="thumb"> <img src="../upload/<?= $row2['img'] ?>" class="img-responsive img-rounded media-preview" alt=""> <span class="zoom-image"><i class="icon-play3"></i></span> </div>
</div>
<div class="caption">
<h6 class="no-margin">
<a href ="video_details.php?id=<?= $row2['id'] ?>" class="text-default"><?= $row2['title'] ?>
</a>
</h6>
</div>
</div>
</div>
<?
}
} ?>
</div>
How I can fix it?
Remove the
$pieces = explode(",", $vedoes);
its useless
make your for loop condition look like this
for($i=0;$i<=count($vedoes);$i++)
Hope it Helps

Parsing page source using PHP

I'm having a lot of trouble parsing the page source of a results page. The results page returns data about businesses in a city. This data includes name, address, phone number, owner name and URL. Any help would be much appreciated.
This is an example of one of the results (There are hundreds in the original file):
<div class="ListingResults_All_CONTAINER ListingResults_Level3_CONTAINER">
<div class="ListingResults_Level3_HEADER">
<div class="ListingResults_All_ENTRYTITLERIGHT">
<div><img src="/external/wcpages/images/L3more.gif" alt="317 at Montgomery"></div>
</div>
<div class="ListingResults_All_ENTRYTITLELEFT">
<div class="ListingResults_All_ENTRYTITLELEFTBOX"><strong><span itemprop="name">317 at Montgomery</span></strong></div>
</div>
</div>
<div class="ListingResults_Level3_MAIN">
<div class="ListingResults_Level3_MAINRIGHT">
<div class="ListingResults_Level3_MAINRIGHTBOX">
<div class="ListingResults_Level3_LOGO"><img src="http://www.centerstateceo.com/external/wcpages/wcwebcontent/webcontentpage.aspx?contentid=2071" class="ListingResults_Level3_LOGOIMG"><div style="width:100%;height:1px;overflow:hidden;"></div>
</div>
<div class="ListingResults_MAINRIGHTBOXDIVIDER" style="width:100%;overflow:hidden;height:1px;">_</div>
<div class="ListingResults_Level3_AFFILIATIONS"></div>
</div>
</div>
<div class="ListingResults_Level3_MAINLEFT">
<div class="ListingResults_Level3_MAINLEFTBOX" itemtype="http://data-vocabulary.org/Address" itemscope="" itemprop="address"><span itemprop="street-address">317 Montgomery St.</span><br><span itemprop="locality">Syracuse</span>, <span itemprop="region">NY</span> <span itemprop="postal-code">13202 </span><div class="ListingResults_Level3_MAINCONTACT"><img src="/external/wcpages/images/maincontact.gif" alt="Mr. Dean Whittles">Mr. Dean Whittles</div>
<div class="ListingResults_Level3_PHONE1"><img src="/external/wcpages/images/phone.gif" alt="Work Phone: (315) 214-4267">(315) 214-4267</div>
</div>
</div>
</div>
<div class="ListingResults_Level3_FOOTER">
<div class="ListingResults_Level3_DESCRIPTION">
<div class="ListingResults_Level3_DESCRIPTIONBOX"></div>
</div>
<div class="ListingResults_Level3_FOOTERRIGHT">
<div class="ListingResults_Level3_FOOTERRIGHTBOX">
<div class="ListingResults_Level3_SOCIALMEDIA"></div>
</div>
</div>
<div class="ListingResults_Level3_FOOTERRIGHT">
<div class="ListingResults_Level3_FOOTERRIGHTBOX">
<div class="ListingResults_Level3_COUPONS"></div>
</div>
</div>
<div class="ListingResults_Level3_FOOTERLEFT">
<div class="ListingResults_Level3_FOOTERLEFTBOX"><span class="ListingResults_Level3_LEARNMORE"><a href="/Restaurants/317-at-Montgomery-7897" class="level3_footer_left_box_a friendly">
Learn More
</a></span><span class="ListingResults_Level3_VISITSITE"> | <a href="http://www.317syr.com" onclick="recordReferralOnClick('20947', '7897', 'W');" target="_blank">
Visit Site
</a></span><span class="ListingResults_Level3_MAP"> | Show on Map</span></div>
</div>
</div>
</div>
PHP Code from Comment:
<?php
$dom = new DOMDocument();
$dom->loadHtml($data);
$spans = $dom->getElementsByTagName('span');
foreach ($spans as $el) {
$children = $el->childNodes->item(1);
if (is_object($children) AND $children->tagName == 'a') {
$url = $children->getAttribute('href');
echo $url;
continue;
}
$user_param = $el->getAttribute('itemprop');
$value = $el->nodeValue;
if ($user_param != "") {
echo $user_param . " " . $value . "\n";
}
}
?>

HOWTO: get data from MYSQL database and then use/show this data in a php page in a while/foreach?

I figured out how to get the data, how to use it in a while loop, but I am stuck on the last part: a loop in a loop.
I have the following code:
<div id="tab1" class="tab_content">
<ul class="columns">
<?php
$result = mysql_query("SELECT * FROM TabContent WHERE TabID = 1");
while($row = mysql_fetch_array($result))
{
echo '<li><img src="images/layouts/'. $row['LayoutName'] .'.png" alt="" />
<div class="info">
<h2>'. $row['LayoutName'] .'</h2>
<p>'. $row['LayoutTiles'] . 'Tiles, '. $row['LayoutLayers'] . 'Layers</p>
</div>
</li>';
}
?>
</ul>
<div class="clear"></div>
<div class="bottom">
<div class="clearfix">
<div class="lfloat"></div>
<div class="rfloat"><a class="hide" href="#" onclick="return false">Cancel</a></div>
</div>
</div>
</div>
<div id="tab2" class="tab_content">
etc etc same as above
The problem I have is with the div with id="tab1" and the next one with id="tab2" etc. I can get an array of tabs using:
<?php
$result = mysql_query("SELECT * FROM Tabs");
while($row = mysql_fetch_array($result))
{
echo 'tab'. $row['TabID'] .;
}
?>
Giving me: Tab1 Tab2 Tab3 etc. Now the hard part, how do I use these so I can make a loop using this to replace my html div ids?
Here's a couple of tutorials that might help you in your struggle:
http://www.freewebmasterhelp.com/tutorials/phpmysql
http://www.homeandlearn.co.uk/php/php.html

Categories