close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

I'm at a loss...lol

Thread began 3/21/2010 1:50 pm by akstudio | Last modified 3/24/2010 4:07 pm by Eric Mittman | 1450 views | 5 replies |

akstudio

I'm at a loss...lol

Im trying to figure something out, and I'm not even sure what terms would describe it, which makes my google searches fruitless....

I have a master/detail page.

The master page lists out the records, and, obviously, the details page, is the details of those records.

What I needed to do was pull data from 3 tables

videos
tags
products

I went and modified the SELECT, it now looks like:

$query_video_library = "SELECT c.product as product_name, b.name as name, a.product as product, a.product_id as product_id, a.small_thumbnail as small_thumbnail, a.title as title, a.description as description, a.video_length as video_length, a.channel_id as channel_id, a.id as linkid, a.`channel_id`, a.`channel_id` FROM videos a INNER JOIN tags b ON a.channel_id = b.id INNER JOIN products c ON a.product_id = c.id";

This works fine. (maybe a better way to handle it, i dunno)

When the page is rendered, they are all displayed.

However, I now need to add in a dropdown that will sort the records by tags.

What I have ended up creating is this:

if(isset($_POST['channel_sort']) or isset($_POST['product']) or isset($_POST['solution'])){
$newchannel = $_POST['channel_sort'];


$query_video_library = "SELECT c.product as product_name, b.name as name, a.product as product, a.product_id as product_id, a.small_thumbnail as small_thumbnail, a.title as title, a.description as description, a.video_length as video_length, a.channel_id as channel_id, a.id as linkid, a.`channel_id`, a.`channel_id` FROM videos a INNER JOIN tags b ON a.channel_id = b.id INNER JOIN products c ON a.product_id = c.id WHERE a.channel_id = '$newchannel'";
} else {

$query_video_library = "SELECT c.product as product_name, b.name as name, a.product as product, a.product_id as product_id, a.small_thumbnail as small_thumbnail, a.title as title, a.description as description, a.video_length as video_length, a.channel_id as channel_id, a.id as linkid, a.`channel_id`, a.`channel_id` FROM videos a INNER JOIN tags b ON a.channel_id = b.id INNER JOIN products c ON a.product_id = c.id";

}

When someone chooses an item from the drop down.... the SQL changes.

This all still works.... somehow.

PROBLEM:

I cannot add in any pagination for some reason. Dreamweaver tells me "video_library" doesn't exist., when it clearly does. The Dreamweaver bindings panel does not show "video_library" and in my server behaviors it says the repeat region "video_library" doesn't exist when i click on it (has red ! ) - it defaults to "channel_sort"

I fear that I will only end up with more problems with this method.

My logic is telling me I need some sort of .. I guess "if" statement all rolled up into one SQL statement, or something.

I still need to add in another drop down for products ... and possibly another for solutions... AND the pagination.

A big thanks to anyone who can shed light on this mess.

Sign in to reply to this post

Eric Mittman

For the pagination you should try adding that to the page before you alter the recordset. If the recordset is too complex and DW has a hard time recognizing it you will not be able to apply the pagination. If you apply it to the recordset in a simpler fashion you should then be able to make an update to the recordset after you add the pagination.

As for the issue you are having with your current setup please describe a little more about what you would like to have occur on this page from the perspective of the user. If I had a better understanding of what the end goal was I would better be able to help answer some questions that you have about it.

Sign in to reply to this post

akstudio

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.

Sign in to reply to this post

web_assist_mail157665

Disable the other dropdown by javascript if the user makes a selection from one of the dropdowns

when the page loads both options will again be available until one of the dropdowns is used

...you can then happily use OR in the select.

Sign in to reply to this post

akstudio

what if a user would like to choose a channel within a certain product?

I need a way for a user to use

drop-down 1 only

OR

drop-down 2 only

OR

drop-down 1 and 2

They should be able to filter any way they like based on the 2 drop-downs. And continue to have the pagination work properly beyond page 1 of the pagination links, which means the drop downs must retain their information, and not reset on page 2 of the pagination

Sign in to reply to this post

Eric Mittman

How DataAssist does this is to store the where part of the query in a variable. When you are setting the variable you can check on your '$newchannel' and '$newproduct' to see if they both have valid values, if so you would write the where portion of the query with an and, if not you should check to see which one has the valid value and write the where clause with only that value.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...