2011-09-08 58 views
1
<?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>"; 

} 
?> 

^^這是我profile.php頁我執行查詢,然後使用一個變量作爲一個鏈接,但鏈接無法正常工作

<?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>&nbsp;'.$song.'</b><br><h10>&nbsp;<a href=/listen.php?u='.$identify.'>(Comments  and more)</a></h10><p>'; 
?> 

^^這是getprofilevideo.php

我的問題是,當我點擊div並嘗試執行onclick ='LinkOnClick($ identify2);'我的頁面不斷向我顯示查詢的最後一項。不過,我需要profile.php來顯示我點擊的實際視頻,而不是查詢的最後一個視頻。爲更好地解釋,請轉至http://www.pearlsquirrel.elementfx.com/profile.php?u=wildcard,並將鼠標懸停在歌曲上時,單擊突出顯示的div,然後可以看到問題。它不斷加載「預覽3」,而不是你點擊的歌曲。我花了數週時間來解決這個問題。任何幫助將不勝感激,感謝您的反饋!

回答

1

很好的一件事...

function LinkOnClick(box) { 
     $('#profile').load('getprofilevideo.php?u=$identify2'); 
} 

你不斷地一遍又一遍地在你的循環再次重新定義這個功能。

其次,你實際上並沒有在函數的代碼中使用box參數。相反,您已經在函數中放置了一個PHP變量,它不會像您想象的那樣工作......

基本上,您打印出的每個函數都帶有硬編碼鏈接。

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將始終使用包含硬編碼字符串值的該函數的最後定義版本。

應該是做的是將javascript函數定義從循環中取出,以便它只定義一次,然後使用「box」參數而不是硬編碼值生成正確的鏈接。

function LinkOnClick(box) { 
     $('#profile').load('getprofilevideo.php?u=' + box); 
} 
+0

非常感謝!你不知道我多麼感激這一點,我一直在努力尋找一個數周的解決方案。非常感謝幫助。謝謝! – Eggo

+0

@Eggo沒問題。另外,如果它回答了你的問題,你可能想接受這個答案。您可以通過點擊左側旁邊的複選標記來完成此操作。 – dqhendricks