close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Show or Hide Repeating Regions-Records Toggle

Thread began 9/27/2009 12:59 am by troyd | Last modified 9/29/2009 1:30 pm by Dave Buchholz | 1743 views | 9 replies |

troyd

Show or Hide Repeating Regions-Records Toggle

This seemed like it should be straight forward to me at first, but now I'm not sure.

If I have a list of records that are displayed in descending order based on ID but would like to hide certain records for a period of time, what would be the best approach?

Basically, I would like to include a radio group or check box within the records Update page that would assign a value to a column. For example, "On" "Off", or "True" "False" and in my case "Available" "Sold". This would keep the record in the database but not display it in the public viewable list.

The records by default would show in the list. But if something needed to be hidden from public view, I would just alter the value in that column and then it would disappear from view. If I wanted it to show again, I would toggle it back.

At first I thought I could use a Search behavior. Then I thought maybe a Sort behavior. This isn't so obvious to me anymore. Any suggestions? Still learning and I want to do it right. (I have all the extensions if needed).

Thanks,
TroyD

Sign in to reply to this post

troyd

Ok, it acured to me that the feature I am trying to include here would be an obvious one to include in a products shopping cart. Then I remember that I had purchased the PowerStore2 but hadn't had a chance to mess with it.
So I set up a local testing version of it and sure enough, on the Products_Update.php page it has the checkbox I am wanting to create.
On that page it simply writes a 1 when checked, into a column of the products database. I think I understand that.

However, on the Products_Results.php page where the public sees the list, I can't figure out exactly how the product shows if given a value of 1, or is hidden if given a value of 0.

I see a WHERE statement for the "ProductLive" column in the recordset. But I can't make sense of it because there are so many other things going on there.
I think it is saying to display records by ID AND ProductLive <> 0, meaning that if a record has an ID and the value of the column ProductLive has a value greater than or lesser than 0, then show that record. But I can't get it to work for me in my DA records.

Am I going in the wrong direction?

TroyD

Sign in to reply to this post

Dave BuchholzBeta Tester

I am going to assume that you are using DataAssist to manage your database.

1st thing to do is to add another field to your database table (I call this archive but you can call it whatever you want) here is a sample of a typical table that I would use

CREATE TABLE `tbl_sample` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`description` text COMMENT 'Description - Max 65,535 Characters (String)',
`image` varchar(100) DEFAULT NULL COMMENT 'Image File - Max 100 Characters (Fixed Length)',
`sortorder` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Controls of order of appearance - higher number equals greater importance',
`archive` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Archive Option (removes this from display in the front end)',
`tstampinsert` int(11) unsigned DEFAULT NULL COMMENT 'insert a unix tstampinsert here using <?php echo time(); ?> in a hidden field in your form',
`tstampupdate` int(11) unsigned DEFAULT NULL COMMENT 'insert a unix tstampinsert here using <?php echo time(); ?> in a hidden field in your form',
PRIMARY KEY (`id`),
FULLTEXT KEY `description` (`description`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='This table stores the product options info (optional)' ;



You can then use the Data Assist Wizard to create the control pages or build them yourself is you wish.

On the public facing pages I add a where statement to my recordset that says only display a record if archive = 0 sample:

SELECT id, description, image FROM tbl_sample WHERE archive = 0 ORDER BY sortorder



This will display only records with an archive value of 0

Hope that gets you going.

Sign in to reply to this post

troyd

Thank you. Yes, I am using Data Assist. I had finally figured out last night what I needed to do, and was close. Your example showed me where I had gone wrong. For some reason I was using "Server Variable" instead of "Entered Value". Not now my public page has...

php:
SELECT * FROM tblTablehere WHERE visible = 1 ORDER BY id DESC


("visible" being my column name). Now it works. Thanks.

Now I would like to display the value in the Admin Detail page, something other than a "1" or a "0". I know there is a way to format that this, but for the life of me I can't find it in any of my books. I know this is a simple code for most, but I'm still learning the hand coding part.
I assume that I create a condition that says 1 is = to "word1" and 0 is = to "word2" but I don't know which process to use here. I thought I had figured it out in the chapter on typecasting but then decided that was not correct. Can someone point me in the right direction? Should I use an if statement?

Thanks,
Troy

Sign in to reply to this post

Dave BuchholzBeta Tester

Tory,

you can use a ternary operator like so:

<?php echo ($row_rsRecordset['visible'] === '1')?'Yes':'No'; ?>
Sign in to reply to this post

troyd

That did it! Thanks.

What I had been trying (and was not working) was this if statement.

php:
<?php

$value 
$row_rsRecordset["visible"];
if (
$value == 0) echo 'No'
if ($value == 1) echo 'Yes'
?>



But clearly I have something in the wrong place. I was thinking there should be some } brackets in there somewhere. (Basic PHP, I'm sure).

Yours worked perfectly. So basically the code you wrote is saying if the value of "visible" is equal to "1" echo "Yes", otherwise echo "No"? Is that correct. Very cool.

Thanks again,
TroyD

Sign in to reply to this post

Dave BuchholzBeta Tester

Troy,

ternary operators are very compact and very powerful so use them often :-)

your code should have read

<?php
$value = $row_rsRecordset["visible"];
if ($value == 1) { echo 'Yes' } else { echo 'No '; }
?>



Alternatively if you have a number of different options you can use a switch statement which is capable of handling a number of options and is cleaner than multiple if statements, in this example I have used Yes, No, and Maybe :-)

switch($row_rsRecordset["visible"]) {
case 0:
echo 'No';
break;
case 1:
echo 'Yes';
break;
default:
// default behaviour if all else fails
echo 'Maybe';
}
Sign in to reply to this post

troyd

Oh, I see now. Thanks.
And thanks for the switch statement. I am already thinking of a use for that on an other project.

TroyD

Sign in to reply to this post

jw291405

Dave,

This pertains to your use of fulltext in the suggested MyIsam table. We are dealing with a fulltext issue at the moment on a InnoDB table for products. We need InnoDB for that and we need a fulltext key. Having to keep the Products table of the Innodb type, would mitigating this situation require a separate MyIsam table used for a search-&-results page with a detail page link to the actual Products table? It feels like a strange logic with having to actively maintain an extra table.

Sign in to reply to this post

Dave BuchholzBeta Tester

According to the MySQL Docs you can only use MyISAM Tables for full text search searches

  Full-text indexes can be used only with MyISAM tables, and can be created only for CHAR, VARCHAR, or TEXT columns.  



Without knowing more about your particular situation it's difficult to say what your best course of action would be.

Sign in to reply to this post
loading

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...