I am executing a query and then using a variable as a link, but the link is not working properly
<?php mysql_connect("localhost","username","password") or die($error);
mysql_select_db("db") or die($error);
$query = "SELECT * FROM music WHERE user='$profilename' ORDER BY id DESC";
$construct = "SELECT * FROM music WHERE user='$profilename' ORDER BY id DESC";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
while ($runrows = mysql_fetch_assoc($run))
{
$title = $runrows['songname'];
$song = $runrows['title'];
$name = $_FILES["file"]["name"];
$user = $runrows['user'];
$thumbnail = $runrows['thumbnail'];
$identify2 = $runrows['id'];
$echovar8 = substr($song,0,35).'...';
$echovar = "<a href=/listen.php?u=$identify2><img src='thumbnails/$thumbnail' width='120' height='80'></a>";
#$description = $runrows['description'];
#$url = $runrows['url'];
if (strlen($song)>34)
{
echo "<script>
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=$identify2');
}
</script><div onmouseover='boxOnHover(this);' onmouseout='boxOffHover(this);' onclick='LinkOnClick($identify2);' onclick='boxOnHover(this);'><table><tr><td>$echovar</td><td> <a href=/listen.php?u=$identify2>$echovar8</a></b></td></tr></table></div><hr><p>";
}
else
echo "<script>
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=$identify2');
}
</script><div onmouseover='boxOnHover(this);' onmouseout='boxOffHover(this);' onclick='LinkOnClick($identify2);' onclick='boxOnHover(this);'><table><tr><td>$echovar</td><td> <a href=/listen.php?u=$identify2>$song</a></b></td></tr></table></div><hr><p>";
}
?>
^^this is my profile.php page
<?php
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "password";
$dbname = "db";
//Connect to MySQL Server
mysql_connect($dbhost, $dbuser, $dbpass);
//Select Database
mysql_select_db($dbname) or die(mysql_error());
// Retrieve data from Query String
$id2 = $_GET['u'];
// Escape User Input to help prevent SQL Injection
$id2 = mysql_real_escape_string($id2);
$run = mysql_query("SELECT * FROM music WHERE id='$id2'");
$getdata10 = mysql_query("SELECT * FROM music WHERE id='$id2'");
while ($runrows = mysql_fetch_assoc($run))
{
$title = $runrows['songname'];
$song = $runrows['title'];
$identify = $runrows['id'];
$name = $_FILES["file"]["name"];
$user = $runrows['user'];
$thumbnail = $runrows['thumbnail'];
$color = $profileresult['color'];
$bubblecolor = $profileresult['bubblecolor'];
}
echo '
<link rel="stylesheet" type="text/css" href="/demos/standalone.css"/>
<script type="text/javascript" src="mp3/flowplayer-3.2.6.min.js"></script>
<!-- this A tag is where your Flowplayer will be placed. it can be anywhere -->
<a
href="mp3/song.mp3"
style="display:block;width:640px;height:385px"
id="player">
</a>
<!-- this will install flowplayer inside previous A- tag. -->
<script>
$f("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.7.swf", {
clip: {
url: "mp3/'.$title.'",
// this style of configuring the cover image was added in audio
// plugin version 3.2.3
coverImage: { url: "thumbnails/'.$thumbnail.'"}
}
});
</script>
<br><b> '.$son开发者_Python百科g.'</b><br><h10> <a href=/listen.php?u='.$identify.'>(Comments and more)</a></h10><p>';
?>
^^this is getprofilevideo.php
my problem is that when I click on the div and try to execute onclick='LinkOnClick($identify2);' my page keeps showing me the last item of the query. However, I need profile.php to display the actual video that I click on, and not the last video of the query. For a better explanation, go to http://www.pearlsquirrel.elementfx.com/profile.php?u=wildcard and when hovering over a song, click the highlighted div, then you can see the problem. It keeps loading "Preview 3" and not the song that you are clicking on. I have spent weeks trying to solve this issue. Any help would be greatly appreciated, thanks for the feedback!
well for one thing...
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=$identify2');
}
you continually redefine this function over and over again in your loop.
Second, you do not actually use the box argument in the function's code. Instead you have placed a PHP variable in the function, which does not work the way you may imagine...
Basically, you are printing out the same function each with a hardcoded link.
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=hardcodedstring1');
}
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=hardcodedstring2');
}
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=hardcodedstring3');
}
Javascript will then always use the last defined version of this function containing your hard coded string value.
What you should do, is take the javascript function definition out of the loop so that it is only defined once, then use the "box" argument instead of a hardcoded value to generate the correct link.
function LinkOnClick(box) {
$('#profile').load('getprofilevideo.php?u=' + box);
}
精彩评论