I made a youtube list where I can click on texts that load youtube videos.
There is only one problem: When I play a video and click on another video link, the video I was playing doesn't stop. So I tried stopping it using jQuery, but no result.
So this is what my php generates:
function generateVideo() {
echo '<script type="text/javascript" src="scripts/video.js"></script>';
$tags = initTags();
$query = '
SELECT * FROM `youtube_links`';
$result = mysql_query($query);
if ( !$result) {
die('Error: '.mysql_error());
}
echo '<div id="content"><table>';
$i = 0;
$className = "";
while ($row = mysql_fetch_array($result)) {
$i++;
if ($i == 1) {
$className = "active";
} else {
$className = "inactive";
}
echo '
<tr>
<td>
<a class="'.$className.'" id="item_'.$i.'" onclick="switchVideo(this)">
'.$row['Title'].'
</a>
</td>
</tr>
';
}
echo '</table></div>';
$query = '
SELECT * FROM `youtube_links`';
$result = mysql_query($query);
if ( !$result) {
die('Error: '.mysql_error());
}
echo '<div id="videoPlayer">';
$i = 0;
$className = "";
while ($row = mysql_fetch_array($result)) {
$link = $row['Link'];
$i++;
if ($i == 1) {
$className = "activePlayer";
} else {
$className = "inactivePlayer";
}
echo '<iframe class="'.$className.'" id="ytplayer'.$i.'" type="text/html" width="640" height="390"
src="'.$link.'?version=3&enablejsapi=1"
frameborder="0">
</iframe>';
}
echo '</div>';
}
And this is my JavaScript:
function switchVideo(obj) {
var idText = obj.id;
var idArray = idText.split("_");
var id = idArray[1];
var videoPlayer = document.getElementById('ytplayer' + id);
var elements = document.getElementsByClassName("activePlayer");
for (var i = 0; i < elements.length; i++) {
elements[i].className = "inactivePlayer";
$(elements[i]).pause();
}
$('.inactivePlayer').each(function() {
$(this).stopVideo();
});
videoPlayer.className = "activePlayer";
}
You can see I added the youtube API to the iframes, so what is going wrong?
It might be a case of async loading of the javascript Youtube API.
Did you checked that?
Greetz, Alex
Related
Good evening.
This construction displays the values in a table that sorts them in alphabetical order.Those for example, if you click on the D link, only the names with letter D should be shown, and so on.
PHP code:
<?php
include ('engine/api/api.class.php');
$table = 'dle_post';
$fields = 'xfields';
$where = 'approve=1';
$multirow = 1;
$start = 0;
$limit = 0;
$xfield = 'actor';
$time = '14000';
$tr_new = 0;
$xfields = $dle_api->load_from_cache ($fields, $time, $xfields);
if( !$xfields ) {
$xfields = $dle_api->load_table ($table,$fields,$where,$multirow,$start,$limit);
$dle_api->save_to_cache ( xfields, $xfields);
}
$stack = array();
foreach($xfields as $value){
if($value[xfields]){
$row = xfieldsdataload($value[xfields]);
if($row[$xfield]){
$rowdata = explode( ",", $row[$xfield]);
foreach($rowdata as $value){
if($value){
$value = trim($value);
array_push($stack, $value);
asort($stack);
}
}
}
}
}
$stack = array_count_values($stack);
foreach($stack as $key => $count){
if($tr_new === 0){
echo '<tr class="new">';
}
echo "<td class='blok'>";
echo "<a href=/" . $xfield . "/";
echo $key;
echo " target='_blank' rel='noopener'>";
echo $key;
echo "</a>";
echo "<span>";
echo "(" . $count . ")";
echo "</span>";
echo "</td>";
$tr_new++;
if($tr_new === 1){
echo '</tr>';
$tr_new = 0;
}
}
JQuery:
$(function () {
var _alphabets = $('.alphabet > a');
var _contentRows = $('#countries-table tbody tr');
_alphabets.click(function () {
var _letter = $(this), _text = $(this).text(), _count = 0;
if(_text == 'all') _text = '.';
_alphabets.removeClass("active");
_letter.addClass("active");
_contentRows.hide();
_contentRows.each(function (i) {
var _cellText = $(this).children('td').eq(0).text();
if (RegExp('^' + _text).test(_cellText)) {
_count += 1;
$(this).fadeIn(400);
}
});
});
});
In page:
<div class="alphabet">
<a class="first" href="#">All</a>
A
B
C
...
<a class="last" href="#">Z</a></div>
<div id="conutries">
<table id="countries-table">
<tbody>
{include file="/code.php"}
</tbody>
</table>
</div>
</div>
Everything works fine, but I encounter such a problem - it turns out correctly to output only one value in one line tr ...
When I try to put a 4 td values to the tr line if($tr_new === 4) - they are not sort by alphabetically, they just displayed like this:
Whats wrong? What need to make this code work fine for me?
Thank you in advance for your help!
How to display this query result in 4 columns
<?php
$direction = $_POST['direction'];
$sumword = $_POST['sumword'];
$length = $_POST['length'];
$con = mysql_connect("localhost","elsha","12q(5PSZ.");
$db = mysql_select_db("elsha",$con);
$query = "SELECT answer FROM words WHERE direction = '$direction' AND sumword = '$sumword' AND sumletter = '$length'";
$result = mysql_query($query);
if(mysql_error()) {
//check that no error has occurred first; take this out in production or make more graceful handling
die(mysql_error());
}
if(mysql_num_rows($result) == 0) {
echo "No Results";
} else {
while($row = mysql_fetch_array($result)) {
echo '<img src="/images/'. $row['0'].'.jpg"><br> '. $row['0'].'<br>';
}
}
?>
like this :
result1 result2 result3 result4
result5 result6 result7 result8
Try this
$i = 0;
while($row = mysql_fetch_array($result)) {
echo '<img src="/images/'. $row['0'].'.jpg"> ';
$i++;
if($i % 4 == 1 && $i!=1){
echo '<br>';
}
}
Use flag like
$flag=0;
while($row = mysql_fetch_array($result)) {
if(($flag%4)==0) {
echo '<tr>';
}
echo '<td><img src="/images/'. $row['0'].'.jpg"><br> '. $row['0'].'</td>';
if(($flag%4)==3) {
echo '</tr>';
$flag=-1;
}
$flag++;
}
replace your while with the following code. try this
$a=1;
while($row = mysql_fetch_array($result)) {
if($a%4==0) {
echo '<img src="/images/'. $row['0'].'.jpg">'. $row['0'].'<br>';
} //4th line with break
else {
echo '<img src="/images/'. $row['0'].'.jpg"> '. $row['0'].' '; // prints first 3 lines
}
$a=$a+1;
}
I think you are trying to display the image name too below the image. Try this:
$i = 1;
while($row = mysql_fetch_array($result)) {
echo '<div class="imgs">';
echo '<img src="/images/'. $row['0'].'.jpg"><br> '. $row['0'];
echo '</div>';
if ($i === 4) {
echo '<div class="clear"></div>';
$i = 1;
} else {
$i++;
}
}
and then style div's
.imgs {
float: left;
/* other styles */
}
.clear {
clear: both;
}
CODE:
<?php
$page = $_GET['page'];
$category = $_GET['cat'];
$your_db = # new mysqli("database","name","password");
if (mysqli_connect_errno())
{
echo 'ERROR!
'.mysqli_connect_errno()
.' - Not connected : '.mysqli_connect_error().'
';
die;
}
else
{
$db_connect = $your_db->select_db("databasename");
if (!$db_connect)
{
echo 'ERROR CONNECT DATA BASE';
die;
}
}
echo '<p>';
$query = "select distinct fldCity from info order by fldCity";
$result = $your_db->query($query);
$number_of_records = $result->num_rows;
for ($i = 0; $i < $number_of_records; $i++)
{
$row = $result->fetch_assoc();
echo '<a href="index.php?cat='.stripslashes($row['fldCity']).'">';
echo stripslashes($row['fldCity']);
echo '</a> / ';
}
echo '</p>';
if ($category)
{
$query = "select fldCompanyLogo, fldCompanyName, fldAddress, fldCity, fldProvince, fldPostalCode, fldMenuLink
from info where fldCity = '$category' and length(fldCompanyLogo) > 0 order by fldCity";
}
else
{
$query = "select fldCompanyLogo, fldCompanyName, fldAddress, fldCity, fldProvince, fldPostalCode, fldMenuLink
from info where length(fldCompanyLogo) > 0 order by fldCity";
}
$result = $your_db->query($query);
$number_of_records = $result->num_rows;
$num_pages = $number_of_records / 7;
if (($number_of_records % 7) > 0 )
{
$num_pages++;
}
if (strlen($page) == 0)
{
$page = 0;
}
else
{
$page = $page * 4;
}
echo '<table border="0" cellspacing="10" cellpadding="10" style="border-collapse: collapse" bordercolor="#111111">';
$row_num = 4;
$result->data_seek($page);
for ($i = $page; $i < $number_of_records; $i++)
{
if ($row_num <= 4)
{
echo '<tr>';
for ($col_num = 0; $col_num < 4; $col_num++)
{
$row = $result->fetch_assoc();
echo '<td>';
show_image(stripslashes($row['fldCompanyLogo']),stripslashes($row['fldCompanyName']));
echo '
';
echo '<b><font face="Tahoma" size="2"><a href="mysite.ca/'.stripslashes($row['fldMenuLink']).'" target="_blank"></font>';
echo '<font face="Tahoma" size="2"><a href="'.stripslashes($row['fldMenuLink']).'" target="_blank">';
echo stripslashes($row['fldCompanyName']);
echo '</a>';
echo '
';
echo stripslashes($row['fldCity']);
echo '
';
echo stripslashes($row['fldProvince']);
echo '
';
echo stripslashes($row['fldPostalCode']);
echo '</td>';
}
$row_num++;
echo '</tr>';
}
else
{
break;
}
}
echo '</table>';
for ($j = 0; $j < $num_pages; $j++)
{
$page_link = $j + 1;
echo '<font face="Tahoma" size="4"><b>'.$page_link.'</b></font> ';
}
echo ' '.$number_of_records;
function show_image($image_name)
{
if (file_exists("'$image_name'"))
{
$dim_img = getimagesize('/images/'.$image_name);
echo '<img src="/images/'.$image_name.'" alt = '.$alt.' border=0 align="bottom"';
echo 'width = '. $dim_img[100] .' height = ' .$dim_img[100] . ' />';
}
else
echo 'Add your image here!';
}
?>
I am totally lost and I can't find the error to why the images from the database isn't loading with the script. I highlighted the area in blue where I believe the error is to be. I just can't find any errors in that particular spot! All I want is the images from a column I have in my database to be fetched and connected to 'echo '
No images are being displayed, and I can't find the error as to why the images aren't showing up
try Convert Image to Base64 String and Base64 String to Image
also why echo ''; you use this its makes no sense
I just learned about moustache.js and i am attempting to create an HTML template. However, the documentation is a bit hard to decipher. I found a good site that explains partials (which I believe I will need). I was hoping someone might be able to just 'get me started' on how I would need to do this.
I have a php file that I need to convert to the template:
PHP:
<div id='board'>
<?php
if ($threads)
{
$count = count($threads);
$perpage = 17;
$startlist = 3;
$numpages = ceil($count / $perpage);
if ($page == 'home') {$page = 1;}
$threadstart = ($page * $perpage) - $perpage;
$i = 0;
echo "<table class='board'>
<tr>
<th width='5%'><img src='".base_url()."img/board/icons/category_icon.png' alt='category_icon'/></th>
<th width='5%'>Tag</th>
<th width='50%'>Subject</th>
<th width='7.5%'>Author</th>
<th width='7.5%'>Replies/Views</th>
<th width='15%'>Last Post</th>
</tr>";
foreach ($threads as $list)
{ $i++;
$thread_owner = $this->thread_model->get_owner($list['owner_id']);
$thread_id = $list['thread_id'];
$query = $this->db->query("SELECT f.tag FROM filter_thread AS ft
INNER JOIN filter AS f ON ft.filter_id = f.filter_id
WHERE thread_id = $thread_id");
$result = $query->result_array();
$trunc_body = $this->thread_model->get_reply_summary($thread_id);
$filter = "";
$filter2 ="";
$ent = "entertainment";
foreach ($result as $string)
{
if ($string['tag'] == $ent) {
$filter2 .= "<div id='entertainment'><p>";
$filter2 .= "<img src='".base_url()."img/board/icons/entertainment_icon.png' title='Entertainment' alt='Entertainment'/>";
$filter2 .= "</p></div>";
} else {
$filter2 .= "<div id='misc'><p>";
$filter2 .= "<img src='".base_url()."img/board/icons/misc_icon.png' title='Misc' alt='Misc'/>";
$filter2 .= "</p></div>";
$filter .= " [".$string['tag']."]";
}
}
if (!$result) { $filter = "" AND $filter2 =""; }
if ($i > $threadstart AND $i <= $threadstart + $perpage)
{
echo "<tr>";
echo "<td>".$filter2."</td>";
echo "<td>".$filter."</td>";
echo "<td title='".$trunc_body['0']['body']."'>".ucfirst($list['subject'])."<div id='filter'><p></p></div></td>";
echo "<td><p>".$thread_owner."</p></td>";
echo "<td align='right'>Replies: ".$list['replies_num']."<br>Views: ".$list['views']."</td>";
$owner = $this->thread_model->get_owner($list['last_post_id']);
echo "<td>".$owner." <br>".$list['replystamp'] ."</td></tr>";
}
}
echo "</table>";
echo "<br>";
echo "Current Page: $page | ";
echo "Page: ";
for ($n = 1; $n < $numpages+1; $n++)
{
echo "<a href=".base_url()."main/home/$n>$n</a> | ";
}
}
?>
</div>
And here is the AJAX
$(function() {
$('#all').addClass('ui-selected')
$( "#selectable" ).selectable({
selected: updatefilters
});
function updatefilters(ev, ui){
// get the selected filters
var template, html;
var $selected = $('#selectable').children('.ui-selected');
// create a string that has each filter separated by a pipe ("|")
var filters = $selected.map(function(){return this.id;}).get().join("\|");
$.ajax({
type: "POST",
url: 'updatefilters',
dataType: 'json',
data: { filters: filters },
success: function(data){
var template = "<div id ='board'>TESTING{{#body}}<table>";
var partials = "{{#subject}}";
//for (i=0 ; i< data.length ; i++)
//{html += "<tr><td>" + data[i].subject + "</td><td>" + data[i].body + "</td></tr>";}
//html += "</table></div>";
var html = Moustache.to.html(template, data, partials);
$('#board').html(html);
}
});
}
});
Im not sure how to navigate through the JSON array with moustache..and as it is, it does not update the page, though the commented out parts DO.
Thanks in advance!
First of all if you are receiving a json string you will need to to parse it (use $.parseJSON(data))
Once you have the data parsed you need to loop throught the JSON attributes.
For example:
If JSON has the following: body: {content: [dataObj:{data:'a'}, dataObj[data:'b']]}
do
<div>{{#body}}<div>
<div>{{#content}}<div>
<div>{{#dataObj}}<div>
<span>{{data}}<span>
If you are using partial, you will need to call them inside the main template.
Check the moustache5 documentation, it has improved a lot.
I have a report that runs and returns 366 records, each containing a thumbnail that is 104 x 80 px. The issue is that the report runs very slowley even though I increased the memory size.
ini_set('memory_limit', '128M');
ini_set('max_execution_time','600');
After writing the SQL query I generate the table items here
generate_table_items($query_all_items);
This then runs through and checks for the image in the columns
function generate_table_items($query){
$columns = array();
$resultset = array();
$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$columncount = 0;
$rowcost = 0;
$rowsale = 0;
while ($row = mssql_fetch_assoc($query)) {
if (empty($columns)) {
$columns = array_keys($row);
echo '<tr><th scope="col" >'.implode('</th><th scope="col" >',get_column_name($columns)).'</th></tr>';
$columncount = sizeof(array_keys($row));
}
$resultset[] = $row;
echo '<tr><td>'.implode('</td><td>',report_image_check($row)).'</td></tr>';
if(in_array($_SERVER['SCRIPT_NAME'],$scriptname)){
$colspan = (count($columns)-2);
echo "<tr><th scope='row'>Documents</th><td colspan='$colspan' >";
$PKID = $row['ID'];
if($row['SumOfTotalCost'] || $row['SumOfSalePrice']){
$rowcost += $row['SumOfTotalCost'];
$rowsale += $row['SumOfSalePrice'];
$get_total = true;
}
$query_docs = mssql_query("select documents.* from dbo.documents where documents.Antiquities_id = $PKID") or die ('get docs query failed ' . mssql_get_last_message());
while($row_docs = mssql_fetch_assoc($query_docs)){
$document = "../documents/" . $row_docs['document'];
echo "<a href='$document' title='opens in a new window' target='_blank' >" . $row_docs['document'] . "</a> | ";
} // End while (list docs)
mssql_free_result($query_docs);
echo "</td></tr>";
myflush();
} // End if all items and all items by value report
} // End While
echo '<tr>';
for($i=0;$i < $columncount-4;$i++){
echo '<td> </td>';
}
echo '<td>Total Cost '. $rowcost.'</td>';
echo '<td>Total Sale '. $rowsale.'</td>';
echo '<td>Total Calculated Difference '. ($rowsale-$rowcost).'</td></tr>';
} // End function
function get_column_name($columns){
$newcol = array();
$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$thecount = 0;
foreach($columns as $col) {
if($thecount == 1 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
// Don't list the PK
} else {
$newcol[] = '<img id="'.$col.'" src="../images/icons/arrow_down.png" alt="click to sort by" onclick="sortby(\''.$col.'\');" />' . $col;
}
$thecount++;
}
/*if(in_array($_SERVER['SCRIPT_NAME'],$scriptname)){
$newcol[] = "documents";
}*/
return $newcol;
}
function report_image_check($row){
global $base_url, $uploaded_images_folder;
$newrow = array();
$imageext = array();
$imageext[0] = ".jpg";
$imageext[1] = ".png";
$imageext[2] = ".gif";
$imageext[3] = ".tiff";
$scriptname = array();
$scriptname[0] = "/reports/all_items.php";
$scriptname[1] = "/reports/all_items_by_value.php";
$PKID = 0;
$thecount = 0;
foreach($row as $rn) {
if(in_array(strtolower(substr($rn,-4)),$imageext)){
$small_img_ext = substr($rn,-4);
$small_img = substr($rn,0,strripos($rn,"."));
$small_img = $small_img . '_140_105' . $small_img_ext;
$newrow[] = '<a href="' . $base_url . $uploaded_images_folder . '/' . $small_img . '" title="click to zoom on image" target="_blank" ><img src="' . $base_url . $uploaded_images_folder . '/' . $rn . '" alt="" width="50px" height="50px" /></a>';
} elseif($thecount == 1 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
$PKID = $rn;
} elseif($thecount == 2 && in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
$newrow[] = "<a href='../index.php?template=10&PKID=$PKID' target='_blank' >$PKID (click to view)</a>";
} else {
$newrow[] = $rn;
}
$thecount++;
myflush();
}
/*if (in_array($_SERVER['SCRIPT_NAME'],$scriptname)) {
$newrow[] = "<a href='#&PKID=$PKID' target='_blank' >Documents (click to view)</a>";
}*/
return $newrow;
} // End function
//// Flushing function
function myflush(){
ob_implicit_flush();
ignore_user_abort();
}
Can anyone see an issue with this code or see why it would take so long or why it crashes firefox? Would printing to pdf function work better?
It'll take a long time because you're nesting SQL queries... executing a second SQL query for every result that has been returned by the first query.... Doing a single query with a JOIN should help performance significantly.
Printing to PDF would almost certainly be slower: you'd eithe rneed a lot of code to position everything correctly in the report yourself, or to use one of the libraries that can take HTML and render it to a PDF (as you're already generating HTML anyway at the moment, this would be additional processing)