Hello,
I am currently developing a review site that requires displaying video reviews. I have created a PHP page that successfully retrieves all records from my video database called reviews.php. I have also created a page that a user gets redirected to when he/she selects a video entitled watch.php.
The problem I'm having is that my PHP query result that I store as a variable does not seem to work as a parameter for my JavaScript redirect function, which is defined at the top of reviews.php. I have provided 2 section of code, the first being my reviews.php page and the second being my watch.php page.
I have included both pages in their entirety in case my problem lies elsewhere but lines of interest are on the reviews.php script: lines 7-23 and 175-183 and the watch.php script lines 45-55.
reviews.php: 7-23 and 175-183
<?php
//You must start the session before information is sent to the browser!
session_start();
include('layouts/header.php');
?>
<script language="JavaScript">
<!-- //JavaScript cloak
function getVideo($video) {
<?php
//$video = "http://localhost/~jfarny/gamePlay/0_introCredits.flv";
$_SESSION['currentVideo'] = $video;
?>
//Set the url
var url = "http://localhost/~jfarny/watch.php"
window.location = url;
}
//-->
</script>
<div id="outer">
<div id="mainWrapper">
<div id="home"><a href="index.php"></a></div>
<ul class="mainNav">
<li><a class="current" href="reviews.php" onMouseOver="setMenu('subNav')" onMouseOut="clearMenu('subNav')">Reviews ↪</a></li>
<li><a href="forums.php">Forums</a></li>
<li><a href="blogs/">Blogs</a></li>
<li><a href="about.php">About</a></li>
</ul>
<div id="subNav" onMouseOver="setMenu('subNav')" onMouseOut="clearMenu('subNav')">
<ul>
<li><a href="allReviews.php">All</a></li>
<li><a href="ps3Reviews.php">Playstation 3</a></li>
<li><a href="xboxReviews.php">Xbox 360</a></li>
<li><a href=pcReviews.php">Windows PC</a></li>
</ul>
</div> <!-- subNav -->
<div class="searchBar">
<p>searchBar</p>
</div> <!-- searchBar -->
</div> <!-- mainWrapper -->
<div id="contentWrapper">
<div class="mainContent">
<div class="breadCrumbs">
<p>Reviews →</p>
</div> <!-- breadCrumbs -->
<!--<form action="results.php" method="post">
<p>Select a platform</p>
<select name="searchtype">
<option value="All">All</option>
<option value="ps3">Playstation 3</option>
<option value="xbox360">Xbox 360</option>
<option value="pc">PC</option>
</select>
<br/>
</form>-->
<?php
require_once ("../dbConnect.php");
// Number of records to display per page:
$display = 5;
// Determine the number of pages to show
if (isset($_GET['p']) && is_numeric($_GET['p'])) {
// If its already been determined...
$pages = $_GET['p'];
} else {
// If it hasn't...
$q = "SELECT COUNT(vId) FROM videos";
$r = @mysqli_query ($dbc, $q);
$row = @mysqli_fetch_array ($r, MYSQLI_NUM);
$records = $row[0];
// Calculate the number of pages...
if ($records > $display) {
// If the number of videos is too great to display on one page
$pages = ceil( $records/$display );
} else {
$pages = 1;
}
} // End of the pages conditional
// Determine where in the database to start displaying results
if(isset($_GET['s']) && is_numeric($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
// Define the sorting variable
$sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'phpDate';
// Determine the sorting order
switch ($sort) {
case 'pt':
$orderBy = 'platform ASC';
break;
case 'mp':
$orderBy = 'maxPrice DESC';
break;
case 'sc':
$orderBy = 'score ASC';
break;
case 'phpDate':
$orderBy = 'phpDate ASC';
break;
default:
$orderBy = 'phpDate ASC';
$sort = 'phpDate';
break;
}
// Make the Query
$q = "SELECT score, pic, title, platform, videoUrl, maxPrice, description, DATE_FORMAT(dateAdded, '%D %M %Y') AS phpDate FROM videos ORDER BY $orderBy LIMIT $start, $display";
$r = @mysqli_query ($dbc, $q);
// Table Header
echo '<table align="left" cellspacing ="0" cellpadding="0" width="619px" style="table-layout:fixed">
<col width=100px>
<tr class="reviewsHeader">
<td align="left"><p class="p4"></p></td>
<td align="left"><p class="p4"></p></td>
<td align="center"><p class="trHeaderLink"><a href="reviews.php?sort=pt">Platform</a></p></td>
<td align="center"><p class="trHeaderLink"><a href="reviews.php?sort=mp">Price</a></p></td>
<td align="center"><p class="trHeaderLink"><a href="reviews.php?sort=sc">Score</a></p></td>
<td align="center"><p class="trHeaderLink"><a href="reviews.php?sort=phpdte">Date Added</a></p></td>
</tr>
';
// Fetch and print all the records
// Set the initial background color
$background = '#eeeeee';
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$background = ($background == '#eeeeee' ? '#ffffff' : '#eeeeee');
echo '<tr class="reviews" bgcolor="' .$background. '">
<td align="left"><img src=' . $row['pic'] . ' alt="VIDEO PIC" /></td>
<td align="left"><p class="titleLink"><a href=javascript:getVideo('. $row['videoUrl'] . ')>' . $row['title'] . '</a></p></td>
<td align="center"><p>' . $row['platform'] . '</p></td>
<td align="center"><p>$' . $row['maxPrice'] . '</p></td>
<td align="center"><p>' . $row['score'] . '</p></td>
<td align="center"><p>' . $row['phpDate'] . '</p></td>
</tr>
';
} // End of while loop
echo '</table>';
mysqli_free_result ($r);
mysqli_close($dbc);
// Make links to other pages if necessary
if ($pages > 1) {
// Add some spacing and start a paragraph:
echo '<br /> <p class="p3">';
// Determine what page the script is on:
$currentPage = ($start/$display) + 1;
// If not the first page, make a previous button:
if ($currentPage != 1) {
echo '<a href="reviews.php?s=' . ($start - $display) . '&p=' . $pages . '$sort=' . $sort . '">Previous</a> ';
}
// Make all the numbered pages:
for ($i = 1; $i <= $pages; $i++) {
if ($i != $currentPage) {
echo '<a href="reviews.php?s=' . (($display * ( $i-1))) . '&p=' . $pages . '$sort=' . $sort . '">' . $i . '</a> ';
} else {
echo $i . ' ';
}
} // End of FOR Loop
// If it's not the last page make a next button:
if ($currentPage != $pages) {
echo '<a href="reviews.php?s=' . ($start + $display) . '&p=' . $pages . '$sort=' . $sort . '">Next</a>';
}
echo '</p>'; // Close the paragraph
} // End of Links section
?>
<div class="breadCrumbs">
<p>Reviews →</p>
</div> <!-- breadCrumbs -->
</div> <!-- mainContent -->
</div> <!-- contentWrapper -->
<?php include('layouts/footer.php')?>
watch.php: 45-55
<?php
//You must start the session before information is sent to the browser!
session_start();
include('layouts/header.php');
?>
<div id="outer">
<div id="mainWrapper">
<div id="home"><a href="index.php"></a></div>
<ul class="mainNav">
<li><a class="current" href="reviews.php" onMouseOver="setMenu('subNav')" onMouseOut="clearMenu('subNav')">Reviews ↪</a></li>
<li><a href="forums.php">Forums</a></li>
<li><a href="blogs/">Blogs</a></li>
<li><a href="about.php">About</a></li>
</ul>
<div id="subNav" onMouseOver="setMenu('subNav')" onMouseOut="clearMenu('subNav')">
<ul>
<li><a href="allReviews.php">All</a></li>
<li><a href="ps3Reviews.php">Playstation 3</a></li>
<li><a href="xboxReviews.php">Xbox 360</a></li>
<li><a href=pcReviews.php">Windows PC</a></li>
</ul>
</div> <!-- subNav -->
<div class="searchBar">
<p>searchBar</p>
</div> <!-- searchBar -->
</div> <!-- mainWrapper -->
<div id="contentWrapper">
<div class="mainContent">
<div class="breadCrumbs">
<p>Reviews → Watch →</p>
</div> <!-- breadCrumbs -->
<div class="videoPlayer">
<?php
$video = $_SESSION['currentVideo'];
echo $video;
echo '<a href= "' . $_SESSION['currentVideo'] . '"
style="display:block; width:619px; height:350px"
id="player">
</a>';
?>
</div> <!-- videoPlayer -->
<script>
flowplayer("player", "flowplayer-3.2.2.swf");
</script>
</div> <!-- mainContent -->
</div> <!-- contentWrapper -->
<?php include('layouts/footer.php')?>
Thanks in advance for any advice/solutions!