我想在每次SQL數據庫中的行都經過並打印到網頁上時將變量傳遞到數組中。從數組中的SQL中捕獲PHP變量並輸出到JavaScript變量
然後每次單擊頁面上的項目時,數據庫中的字段中的某個變量就會被捕獲到JavaScript變量中,因此會彈出一個新窗口,其中SQL字段'channel_name'作爲url。
我相信我快到了,但JavaScript變量只保存最後一個SQL'channel_name'的變量。
我希望我做的意義......
這裏是我的代碼進入低谷數據庫,並打印出每個元素:
$chResult = mysql_query($chSQL);
if ($chResult) {
$chNum = mysql_num_rows($chResult);
if ($chNum>0) {
while($row = mysql_fetch_array($chResult)) {
if ($row['is_live']=="1") {
$whatIsLive = "true";
} else {
$whatIsLive = "false";
}
//CREATE THE ARRAY
$chName = array();
//ADD ARRAY VARS FROM CHANNEL_TITLE FIELD
$chName[] = ($row['channel_title']);
//PRINT CHANNEL INFORMATION TO PAGE
echo
'<li id="'.$row['channel_id'].'" class="list-group-item col-xs-12 col-sm-6 col-md-4 col-lg-3">
<div class="item">
<div class="item-head">
<div class="badges">';
if ($row['is_live']=="1") {
echo '<span class="badge-live">Live</span>';
}
echo '
</div>
</div>
<div class="item-image">
<a href="'.SERVERPATH.'channels/'.urlencode($row['channel_title']).'"
//TARGET FOR JAVASCRIPT POPUP WINDOW
target="PromoteFirefoxWindowName"
onclick="openFFPromotionPopup();
return false;"
data-islive="'.$whatIsLive.'"
title="'.$row['channel_title'].'">';
$activeSSImage = 'userData/'.$row['user_id'].'/channelImages/ss_'.$row['channel_id'].'_t.jpg';
$defaultSSImage = 'images/ss_default.jpg';
if (file_exists($activeSSImage)) {
echo '<img src="'.$activeSSImage.'?rand='.rand(0, 99999999).'" alt="'.$row['channel_title'].'" width="250" height="200">';
} else {
echo '<img src="'.$defaultSSImage.'" alt="'.$row['channel_title'].'" width="250" height="200">';
}
echo '
<span class="image-cover"></span>
<span class="play-icon"></span>
</a>
</div>
</div>
</div>
</li>';
}
} else {
echo '';
}
} else {
echo '';
}
該變量被卡在JavaScript中允許的與渠道/ CHANNEL_NAME鏈接到一個新的窗口彈出:
<script type="text/javascript">
var theChannel = <?php echo(json_encode($chName)); ?>;
var windowObjectReference = null; // global variable
function openFFPromotionPopup() {
if(windowObjectReference == null || windowObjectReference.closed)
/* if the pointer to the window object in memory does not exist
or if such pointer exists but the window was closed */
{
windowObjectReference = window.open("channels/"+theChannel,
"PromoteFirefoxWindowName", "resizable,scrollbars,status");
/* then create it. The new window will be created and
will be brought on top of any other window. */
}
else
{
windowObjectReference.focus();
/* else the window reference must exist and the window
is not closed; therefore, we can bring it back on top of any other
window with the focus() method. There would be no need to re-create
the window or to reload the referenced resource. */
};
console.log("function complete");
console.log(theChannel);
}
</script>
說我拿到打印的頁面兩個通道,但是當我點擊它們中的變量是唯一持有輸入最後輸出的頻道的名稱。因此只能打開最後一個輸出通道窗口。
我試圖達到的效果就像在http://onperiscope.com/上發生的情況,爲您提供更好的主意。
我意識到我可能沒有提供足夠的信息,所以請問,我會盡量提供儘可能多的信息。
謝謝
現在的問題在於調用數組。當你點擊一個流時,該數組會被調用,但它會輸出整個數組,而不僅僅是點擊的流。 –