pbrad
Posts: 58
|
| Posted: 12/23/2009, 11:35 AM |
|
Hi,
I am sure that this is simple but I am really struggling with it.
I have a panel that houses a form that houses an object. I want to hide the panel if the record does not exist but I can't seem to figure out the right syntax to get the value of the object:
if ($Panel1->Form1->Text1->GetValue() == "")
$Panel1->Visible=False;
Am I on the right path? If so, what is the right way to access Text1? I am adding this code on a beforeshow event of the panel.
Thanks,
Pete
_________________
Pete
CCS 4
MySQL
PHP |
 |
 |
datadoit
|
| Posted: 12/23/2009, 5:18 PM |
|
The panel doesn't know anything about the existence of the record, since
it's BeforeShow is occurring before the display of the record.
Conversely, if you attempt to check for the existence of the record in
the form's BeforeShow, the logic for dealing with the parent Panel has
also already occurred. Thus you can't hide it there either.
What you'll need to do is put a separate record check either in the
panel's BeforeShow, or in the Page's BeforeShow. Something like:
global $YourConnection;
$db = new clsDBYourConnection();
$SQL = "SELECT * bla bla bla"; //the same SQL used for the record form
$db->query($SQL);
if ($db->ds->RecordsCount == 0) {
$Container->YourPanel->Visible = false; //this will also hide any
child components within, and should not run the SQL again there either
}
else {
$Container->YourPanel->Visible = true;
}
$db->close();
|
|
|
 |
pbrad
Posts: 58
|
| Posted: 12/24/2009, 4:11 AM |
|
Thanks, that makes sense. I obviously need to get a better understanding of the sequence of events of the building and presentation of the page.
Cheers,
Pete
_________________
Pete
CCS 4
MySQL
PHP |
 |
 |
pbrad
Posts: 58
|
| Posted: 12/24/2009, 5:08 AM |
|
Sorry to be a pain but I am still having a problem. My exact code is:
global $WebPort;
$db = new clsDBWebPort();
$SQL = "SELECT page_content FROM pages WHERE Title = '{Expr0}' ";
$db->query($SQL);
if ($db->ds->RecordsCount == 0) {
$Container->Panel3->Visible = false;
}
else {
$Container->Panel3->Visible = true;
}
$db->close();
When I run the page, the tab (Panel3) is hidden, if I change both conditions to true, the tab is shown with the content so it is obviously not finding the record. Can you see anything glaring with my syntax? I have tried running it on beforeshow of the tab panel and also of the parent panel with the same results, I have also tried the following sql statements:
$SQL = "SELECT * FROM pages WHERE Title = '{Test1}' ";
$SQL = "SELECT * FROM pages WHERE Title = 'Test1' ";
_________________
Pete
CCS 4
MySQL
PHP |
 |
 |
datadoit
|
| Posted: 12/24/2009, 7:23 AM |
|
When using the Visual Query Builder (VQB), CodeCharge allow you to
define those custom parameters and handles the logic behind the scenes
for you. However, in this case you need to handle that logic yourself.
So what is {Expr0}? Is it getting a value from a control, from the URL,
from a session variable, etc.? So your SQL will look something like:
$SQL = "SELECT page_content FROM pages WHERE Title = '" .
CCGetParam("id","") . "'";
or
$SQL = "SELECT page_content FROM pages WHERE Title = " .
CCToSQL(CCGetSession("page_id",""), ccsText);
Also, if you're doing this in the Panel's BeforeShow, you could refer to
the Panel via:
$Component->Visible = false/true;
I don't have CCS open right now, but verify that if there's a property
setting for Visibility for a panel, then make sure it's set to 'Dynamic'.
Finally, if all else still fails, comment out all of the conditions and
just see if the component can be programmatically hidden via
$Component->Visible = false, then work your way back through your
conditions. When programming in PHP, make the echo() function your
friend so you can see what's happening when and where. ie:
[...]
$SQL = "SELECT page_content FROM pages WHERE Title = '" .
CCGetParam("id","") . "'";
echo "SQL: " . $SQL . "<br>";
if ($db->ds->RecordsCount == 0) {
echo "No records!<br>";
}
else {
echo "I see records!<br>";
}
[...]
|
|
|
 |
pbrad
Posts: 58
|
| Posted: 12/24/2009, 8:09 AM |
|
Thanks very much for your help, I really appreciate it. At this point, I am experimenting with a different table because I haven't created the products table yet so I have been using a dual field table (title and page_content) and then trying to determine if a record exists where the title is xxx and then displaying a tab with the page_content.
In reality, what I am trying to do is to have a product detail page that has multiple tabs on it. each tab contains different information about that product from that product same product record but not all products have all of the attributes defined.
For example, I may have a product with a detailed description field. If that field is defined, I want to show the tab with the detailed description showing, otherwise I don't want to show the tab at all.
I have the visibility of the tab working but I haven't managed to get the sql accessing the record yet to provide the conditions of visibility. I will work with your code above to try and get it working but I am thinking that I need something more like:
if ($db->ds->f('detailed_description') == "") {
rather than if ($db->ds->RecordsCount == 0) {
I will apply the approach of using echo to troubleshoot this, it should be a big help.
Cheers,
Pete
_________________
Pete
CCS 4
MySQL
PHP |
 |
 |
datadoit
|
| Posted: 12/24/2009, 1:03 PM |
|
Yes, there may be an issue with DataSource->RecordsCount property for
forms. Will have to check into that. It may only work with grids
(possibility for more than one record). This would also work:
global $YourConnection;
$db = new clsDBYourConnection();
$SQL = "bla bla bla";
$db->query($SQL);
$Result = $db->next_record(); //all result sets start at zero, thus
this will set the record pointer at the first possible record.
if ($Result) {
//you have a record!
}
else {
//you don't!
}
$db->close();
|
|
|
 |
damian
Posts: 838
|
| Posted: 12/24/2009, 2:20 PM |
|
also echo your sql query to see that it is producing the query you think it is...
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
pbrad
Posts: 58
|
| Posted: 12/24/2009, 7:05 PM |
|
Thanks guys, I will buckle down and figure it out given your helpful advice.
Merry Christmas,
Pete
_________________
Pete
CCS 4
MySQL
PHP |
 |
 |
|