else {
while($row = mysql_fetch_array($result)) {
$artistname = $row['artistname'];
$songname = $row['songname'];
$songid = $row['songid'];
?>
<br />
<p><?php echo "$artistname"; ?></p>
<p><?php echo "$songname"; ?></p>
<script type='text/javascript' src='jwplayer.js'></script>
<div id='mediaspace1'>This text will be replaced</div>
<script type='text/javascript'>
jwplayer('mediaspace1').setup({
'flashplayer': 'player.swf',
'file': 'uploads/songs/<?php echo "$songid"; ?>',
'controlbar': 'bottom',
'width': '350',
'height': '24'
});
</script>
Code not looping correctly
Page 1 of 19 Replies - 1938 Views - Last Post: 08 February 2012 - 08:04 PM
#1
Code not looping correctly
Posted 08 February 2012 - 10:06 AM
I am using jwplayer to play music that has been uploaded to my server. The code is not looping to pull all of the music correctly, as of now it only pulls the most recent song that has been uploaded. Any ideas on what I am doing wrong?
Replies To: Code not looping correctly
#2
Re: Code not looping correctly
Posted 08 February 2012 - 10:42 AM
That's because you're loading the same script and function call over and over again. Concentrate on organizing your code properly and you won't have these problems.
#3
Re: Code not looping correctly
Posted 08 February 2012 - 10:53 AM
How would I make it load the next available song from the server? Sorry to ask but I'm just unsure
#4
Re: Code not looping correctly
Posted 08 February 2012 - 10:59 AM
You're unsure because you're thinking that this code all executes in the same place. What's really happening is that PHP sends the Javascript to the browser several times and the browser executes each of the function calls one at a time. You just see the last result.
#5
Re: Code not looping correctly
Posted 08 February 2012 - 12:39 PM
So would I want to create another loop along with the loop pulling the info from the database?
#6
Re: Code not looping correctly
Posted 08 February 2012 - 12:56 PM
From the looks of things:
You are outputting that multiple times on the page, you have multiple divs with the id "mediaspace1", it's not unusual to see Javascript act unpredictably when you have multiple elements with the same id and then you try to reference an element by id. Id's should be unique.
<script type='text/javascript'>
jwplayer('mediaspace1').setup({
'flashplayer': 'player.swf',
'file': 'uploads/songs/<?php echo "$songid"; ?>',
'controlbar': 'bottom',
'width': '350',
'height': '24'
});
</script>
You are outputting that multiple times on the page, you have multiple divs with the id "mediaspace1", it's not unusual to see Javascript act unpredictably when you have multiple elements with the same id and then you try to reference an element by id. Id's should be unique.
#7
Re: Code not looping correctly
Posted 08 February 2012 - 01:39 PM
That div is calling the function correct? Im confused, Im sorry
#8
Re: Code not looping correctly
Posted 08 February 2012 - 02:38 PM
A div is just a divider. It calls nothing. Try this script:
What happens?
Why?
<?php
echo "<script type='text/javascript'>var num = 0;</script>";
for($i = 0; $i < 4; $i++) {
echo "<script type='text/javascript'>num++;alert('Hi '+num);</script>";
}
?>
What happens?
Why?
#9
Re: Code not looping correctly
Posted 08 February 2012 - 07:20 PM
Okay youre basically cancelling out each function because you have two scripts doing something similar.. I understand but the function in my code pulls the player and the song and then places it inside the div with the correct ID "<div id='mediaspace'>media</div>"
#10
Re: Code not looping correctly
Posted 08 February 2012 - 08:04 PM
Yes. It does that over and over again until the last time. Then it stops, leaving only the last loaded version in the div.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|