I'm using JWPlayer6 (non-commercial version) and I'm facing a serious problem, using a while loop to loop over all videos from a MySQL database using PHP. Unfortunately, the web page just shows one video from MySQL. When I checked the code in Chrome, I saw that inside the <div id='my-video'></div>, there's nothing to show. How should I fix the problem?
<?php
$result = mysql_query("SELECT * FROM schoolvideo GROUP BY folderName ORDER BY id desc");
while($data = mysql_fetch_array($result)) {
$id = $data['id'];
$video = $data['video'];
$folderName = $data['folderName'];
?>
<div class="square">
<div id='my-video'></div>
<script type="text/javascript">
jwplayer('my-video').setup({
file: 'http://abc.com/video/<?php echo $folderName; ?>/<?php echo $video; ?>',
width: '370',
height: '270',
primary: 'flash',
image: 'http://abc.com/img/poster.png',
autostart: false
});
</script>
</div>
<?php
}
?>
Your loop will generate multiple divs with the same id "my-video". You should make them unique.
<div id='my-video-<?php echo $id ?>'></div>
...
jwplayer('my-video-<?php echo $id ?>').setup({...
Related
I fetched some div elements from database with this code :
<?php
$getTickets = mysqli_query($db, "SELECT * FROM usersTicket");
while ($row = mysqli_fetch_array($getTickets)) {
?>
<div class="tickets">
<div class="ticket"><?php echo $row['ticketText'] ?></div>
</div>
<?php
}
?>
How can I get the number of these div elements that fetched from database ?
Use this if you want to get the number of divs returned from the database.
$number_of_divs = mysqli_num_rows($getTickets);
You could use jQuery for that:
$(document).ready(function() {
var ticketclassnr = $(".tickets").length;
});
I had an image slider that was working fine with solely html, but now that I have introduced PHP to generate the address for each image from a database, the slideshow loops unexpectedly when it first displays. After this it's fine and the images cycle normally.
Any help?
The result: http://colejohnsontrialsite.com/view.php
My Code:
<script>
$("#slideshow > div:gt(0)").hide();
setInterval(function() {
$('#slideshow > div:first')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slideshow');
}, 3000);
</script>
<div id="slideshow" style="float:left;">
<?php
$con=mysqli_connect("localhost","username","pass","database_name");
$result = mysqli_query($con,"SELECT * FROM gifs");
while($row = mysqli_fetch_array($result)) {
echo ' <div> <img id="slideshow" src="' . $row['addresses'] . '">'; echo "</img></div>";
}
mysqli_close($con);
?>
</div>
I'm working on this project trying to create a simple site where a user can input information then on a different page that same information is displayed.
I am using JQuery to refresh the page and .load new content, MySQL to store the information, and PHP to insert and retrieve that information.
The problem I am having now is i'm using Javascript to update the page and .fadeIn the data but currently it is just fading out and fading in ALL of the data. What I want it to do is to keep the current data the same and ONLY fade in the new data.
Here is my JQuery function:
<script type="text/javascript">
$(document).ready(function() {
var refreshId = setInterval(function() {
$("#responsecontainer").fadeOut('fast').load('output.php');
}, 3000);
$.ajaxSetup({ cache: false });
});
</script>
Here is my PHP called 'output.php':
<?php include_once('db_connect.php'); ?>
<?php include_once('input.php'); ?>
<?php
//query the database
$query = mysql_query("SELECT * FROM notes ORDER BY ID DESC");
//fetch the results / convert results into an array
while($rows = mysql_fetch_array($query)):
$title = $rows['notestitle'];
$text = $rows['notestext'];
?>
<div id="title">
<h1><?php echo "$title<br>"; ?></h1>
</div>
<div id="text">
<h2><?php echo "$text<br>"; ?></h2>
</div>
<?php endwhile; ?>
And here is the code for the page that is displaying the info:
<?php include_once('db_connect.php'); ?>
<?php include_once('input.php'); ?>
<div id="header"></div>
<div id="responsecontainer">
<?php include_once('output.php'); ?>
</div>
Let me know if you need me to provide anything else or if something is unclear to you.
Thanks for your time.
Use this simple query with limit
SELECT * FROM notes ORDER BY ID DESC LIMIT 1
I have an application here where I am using jwplayer in basic jquery slider: APPLICATION
Info for basic jquery slider here: http://basic-slider.com/
Now this is what I have found out, if a slider contains multiple videos, then it displays the slider, but if a slider has one video only, it does not display video or slider.
Now what is strange is if I replace the videos for images, then it works if I have a single image as it does not display the slider but displays the image, this is fine. But my question is how to do the same thing for the video?
Here is demo for slider with images: APPLICATION
Below is code for video and slider:
$vidquery = "SELECT s.SessionId, q.QuestionId, v.VideoId, VideoFile
FROM Session s
INNER JOIN Question q ON s.SessionId = q.SessionId
INNER JOIN Video_Question vq ON q.QuestionId = vq.QuestionId
INNER JOIN Video v ON vq.VideoId = v.VideoId
WHERE s.SessionId = ?";
$vidqrystmt=$mysqli->prepare($vidquery);
// You only need to call bind_param once
$vidqrystmt->bind_param("i",$session);
// get result and assign variables (prefix with db)
$vidqrystmt->execute();
$vidqrystmt->bind_result($vidSessionId,$vidQuestionId,$vidVideoId,$vidVideoFile);
$arrVideoFile = array();
while ($vidqrystmt->fetch()) {
$arrVideoFile[ $vidQuestionId ][] = basename($vidVideoFile);
}
$vidqrystmt->close();
?>
<form action='results.php' method='post' id='exam'>
<?php
//start:procedure video
$vid_result = '';
if(empty($arrVideoFile[$key])){
$vid_result = ' ';
}else{
?>
<div id="banner-video_<?php echo $key; ?>">
<ul class="bjqs">
<?php
$i = 0;
foreach ($arrVideoFile[$key] as $v) { ?>
<li><div id="myElement-<?php echo $key.'-'.$i; ?>">Loading the player...
<script type="text/javascript">
jwplayer("myElement-<?php echo $key.'-'.$i; ?>").setup({
file: "<?php echo 'VideoFiles/'.$v; ?>",
width: 480,
height: 270
});
<?php $i++; ?>
</script>
</div>
</li>
<?php } ?>
</ul>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#banner-video_<?php echo $key; ?>').bjqs({
animtype : 'slide',
height : 300,
width : 700,
responsive : true,
randomstart : false,
automatic : false
});
});
</script>
<?php
}
//end:procedure video
?>
</div>
</form>
UPDATE:
If anyone knows how to code it so that if it is able to detect if single video, then do not place it in slider, then I believe this could solve it.
What I am saying is that by your example it looks like all your slider does it slide a image or video over and display the next or previous, but if you have only one item why not just skip all that entirely.
You have an array : $arrVideoFile
You can use count($arrVideoFile); to get the total values in the array.
So
if(count($arrVideoFile) != 0 || $arrVideoFile) != 1)
{
//do the stuff you pasted above
}
else
{
//if(array == 0) maybe show a default image
//if(array == 1) lets just show that
//if image show <img> if video show <object> or in your case
//<div id="myElement-<?php echo $key.'-0'; ?>"></div>
}
Let me know if this helps
sorry if the title is a little.. vague i couldnt pin it down.
So i am developing a friend request system which works i guess similar in concept to facebook. So you get a request and it lists them without a page reload.
However i get the div 'refreshing' or so i think i cant test the php which is where i have a problem, i will post the relevent code and files below.
It may look a little long winded but it shouldnt be too bad in reality. My php code should keep executing the query which is looking at the database in the updateFriendBox.php however it doesnt seem to be doing this. My code may be messy as well so I apologise.
myaccount.php
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript">
function refreshDiv()
{
$.get('updateFriendBox.php', function(data){$('#refresh').html(data);});
}
$(function()
{
refreshDiv();
setInterval(refreshDiv, 5000);
});
function box(x){
if($('#'+x).is(":hidden")){
$('#'+x).slideDown(200);
} else {
$('#'+x).hide();
}
}
</script>
<?php
$addBox = '<div style="display:inline; padding:5px;">
Show/Hide Friend Requests
</div>';
// a bit further down in the code where its all called:
<? echo $addBox; ?></span>
<div class="friendSlide" id="fRequ" style="height:240px; overflow:auto;">Your friend requests: <br />
<div id="refresh"> <?php // this is where the refresh call is ?>
</div>
</center>
</div>
</div>
</div>
updateFriendBox.php:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language="javascript" type="text/javascript">
function acceptFriendRequest(x) {
var url = "friendParse.php";
$.post(url,{ request: "acceptFriend", reqID: x}, function(data){
$("#req"+x).html(data).show().fadeOut(5000);
});
}
function denyFriendRequest(x) {
var url = "friendParse.php";
$.post(url,{ request: "denyFriend", reqID: x}, function(data){
$("#req"+x).html(data).show().fadeOut(5000);
});
}
</script>
</head>
<body>
<?php
include 'dbc.php';
$sql = "SELECT * FROM friendRecu WHERE mem2='" . $_SESSION['user_id'] . "' ORDER BY id ASC LIMIT 10";
$query = mysql_query($sql)or die(mysql_error());
$num_rows = mysql_num_rows($query);
if($num_rows < 1) {
echo "No friend requests";
} else {
while($row = mysql_fetch_array($query)){
$requestID = $row['id'];
$req = $row['mem1'];
$sqlName = mysql_query("SELECT full_name FROM users WHERE id='$req'");
while($row = mysql_fetch_array($sqlName)){
$requesterName = $row['full_name'];
}
echo '<hr /><table width="100%", cellpadding="5"><tr><td width="17%" align="left"><div style="overflow:hidden; height:50px; color:white;"></div></td> <td width="83%">' . $requesterName . ' added you as a friend
<span id="req' . $requestID . '">
Accept
||
Deny
</span></td></tr>
</table>';
}
}
?>
I think you are having a problem because your updateFriendBox.php is returning too much. Remove all that inline JS code, place it in an include file, and include it from myaccount.php. You also shouldn't have <head> and <body> sections in your updateFriendBox.php file.
The ajax call here doesn't create a whole new page, you're getting additional HTML to add to the original page.
So the only thing you should have there is your SQL query, the loop, and your HTML output for each data row.