well basically, the page is a "video library" - a page which returns all records from the db.
On this page I am pulling records from 3 tables:
//**************
SELECT
videos.product,
videos.product_id,
videos.small_thumbnail,
videos.title,
videos.description,
videos.video_length,
videos.channel_id,
videos.ID as linkid,
tags.ID,
tags.name,
products.product,
products.ID
FROM
videos
INNER JOIN tags ON (videos.channel_id = tags.ID)
INNER JOIN products ON (videos.product_id = products.ID)
//**************
I am displaying the video information, associated channel and product.
Obviously, this page needs pagination.
On top of all that, I need 2 drop-downs. One for channels, and one for products. These drop-downs will allow a user to sort by either channel, OR product, and thus, return the results based on that input. These drop-downs connect to the appropriate table for their data.
Somehow, after many hours or work, I managed to get this almost working. The problem I current have is the drop-downs. In my Select I am doing this:
//*****
if(isset($_REQUEST['channel_sort']) or isset($_REQUEST['product_sort']) or isset($_REQUEST['solution'])){
$newchannel = $_REQUEST['channel_sort'];
$newproduct = $_REQUEST['product_sort'];
//$newsol = $_POST['solution'];*/
$query_video_library = "SELECT
videos.product,
videos.product_id,
videos.small_thumbnail,
videos.title,
videos.description,
videos.video_length,
videos.channel_id,
videos.ID as linkid,
tags.ID,
tags.name,
products.product,
products.ID
FROM
videos
INNER JOIN tags ON (videos.channel_id = tags.ID)
INNER JOIN products ON (videos.product_id = products.ID)
WHERE
videos.channel_id = '$newchannel' OR videos.product_id = '$newproduct'";
} else {
$query_video_library = "SELECT
videos.product,
videos.product_id,
videos.small_thumbnail,
videos.title,
videos.description,
videos.video_length,
videos.channel_id,
videos.ID as linkid,
tags.ID,
tags.name,
products.product,
products.ID
FROM
videos
INNER JOIN tags ON (videos.channel_id = tags.ID)
INNER JOIN products ON (videos.product_id = products.ID)";
}
//*****
The OR is messing me up. If i use AND, it works as intended, however, forces a user to choose from both drop-downs.
I had to do some custom hacks with the drop downs in order for them to work with pagination (tom-muck's list) - by default, the drop downs would reset and show the first channel, every time you used the pagination links. It was passing the current value, along with the chosen one, and returning all kinds of oddities.
Here is the pagination with dropdowns:
//*****
<?php
$channel = '';
if (isset($_REQUEST['channel_sort']) && !empty($_REQUEST['channel_sort'])) {
$channel = 'channel_sort='.$_REQUEST['channel_sort'];
}
for ($i=0; $i <= $totalPages_video_library; $i++) {
$TFM_counter = ($i) * $maxRows_video_library + 1;
$TFM_endCounter = min($totalRows_video_library,$TFM_counter + $maxRows_video_library - 1);
if($i != $pageNum_video_library) {
//printf('<a href="'."%s?pageNum_video_library=%d%s", $currentPage, $i, $queryString_video_library. $channel .'">');
echo '<a href="'.$currentPage.'?pageNum_video_library='.$i.$queryString_video_library.'&'.$channel.'">';
echo "$TFM_counter-$TFM_endCounter</a>";
}else{
echo "<strong>$TFM_counter-$TFM_endCounter</strong>";
}
if($i != $totalPages_video_library) echo " | ";
}
?>
<form id="form1" name="form1" method="post" action="<?php echo $currentPage;?>">
<label>
<select name="channel_sort" class="input_styles_sm" id="channel_sort">
<option value="channel">Channel</option> <?php
do {
?>
<option value="<?php echo $row_sort_channel['ID'];
if (isset($_REQUEST['channel_sort']) && $_REQUEST['channel_sort'] == $row_sort_channel['ID']) {
echo 'selected="selected"';
}
?>"><?php echo $row_sort_channel['name']?></option>
<?php
} while ($row_sort_channel = mysql_fetch_assoc($sort_channel));
$rows = mysql_num_rows($sort_channel);
if($rows > 0) {
mysql_data_seek($sort_channel, 0);
$row_sort_channel = mysql_fetch_assoc($sort_channel);
}
?>
</select>
</label>
<!-- second dropdown -->
<select name="product_sort" class="input_styles_sm" id="product_sort">
<option value="channel">Product</option> <?php
do {
?>
<option value="<?php echo $row_sort_product['ID'];
if (isset($_REQUEST['product_sort']) && $_REQUEST['product_sort'] == $row_sort_product['ID']) {
echo 'selected="selected"';
}
?>"><?php echo $row_sort_product['product']?></option>
<?php
} while ($row_sort_product = mysql_fetch_assoc($sort_product));
$rows = mysql_num_rows($sort_product);
if($rows > 0) {
mysql_data_seek($sort_product, 0);
$row_sort_product = mysql_fetch_assoc($sort_product);
}
?>
</select>
<input name="" type="submit" value="Submit" />
</form>
//*****
So anyway, at this point, I have it almost working, except for the OR in the select.