This topic is locked

Conditional display of field

2/1/2009 8:11:59 PM
PHPRunner General questions
K
kjonmyway author

I have searched and searched, and can't figure out what I am doing wrong.
I need to alter the view, list and edit pages for a conditional statement.
I have a table with a field named showimages, with a possible value of yes or no.

I also have a field of img1, img2, img3 with filenames.
Before the view, list and edit pages are processed, I would like to check if the value of showimages is yes, and if it is, display the img1, img2 and img3 fields, and if not, don't display them.
In the View Page, Before Display (same with edit and list pages) I have this in the Table Events -
[codebox]global $conn;

$strSQLExists = "select * from rslistings";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data['showimages']=='yes') {

$xt->assign("img1_fieldblock",true);

$xt->assign("img2_fieldblock",true);

$xt->assign("img3_fieldblock",true);
} else {

$xt->assign("img1_fieldblock",false);

$xt->assign("img2_fieldblock",false);

$xt->assign("img3_fieldblock",false);
}[/codebox]
This seems to work for the List page, but not for the Edit and View pages, the fields display no matter what.
Any help is GREATLY appreciated.

A
alang 2/1/2009

As a suggestion, I would have thought you should have a WHERE clause in your SQL. Currently you appear to be selecting all records from the rlistings table and then only checking the "showimages" field from the first record.

K
kjonmyway author 2/1/2009

My query and the associated code is actually more complicated. I just used an example of what I was trying to do, because the query is not the issue, it is the display of the field in the List, and Edit pages that is the issue.
But, thanks for the comment anyway!

hichem 2/2/2009

I have searched and searched, and can't figure out what I am doing wrong.

I need to alter the view, list and edit pages for a conditional statement.
I have a table with a field named showimages, with a possible value of yes or no.

I also have a field of img1, img2, img3 with filenames.
Before the view, list and edit pages are processed, I would like to check if the value of showimages is yes, and if it is, display the img1, img2 and img3 fields, and if not, don't display them.
In the View Page, Before Display (same with edit and list pages) I have this in the Table Events -
[codebox]global $conn;

$strSQLExists = "select * from rslistings";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);
if($data['showimages']=='yes') {

$xt->assign("img1_fieldblock",true);

$xt->assign("img2_fieldblock",true);

$xt->assign("img3_fieldblock",true);
} else {

$xt->assign("img1_fieldblock",false);

$xt->assign("img2_fieldblock",false);

$xt->assign("img3_fieldblock",false);
}[/codebox]
This seems to work for the List page, but not for the Edit and View pages, the fields display no matter what.
Any help is GREATLY appreciated.


I have been trying to do the same and got it to work for the view page (which am assume is the case for you as well). However the list page refers to fieldheader instead I think.

The difference between list and view pages is from what I understand:

view page: displays a single record.you can disable field blocks depending on the value of the field or another if condition. this would hide the field block only for that record

list page: contains a list of records so if you want to hide the column, it will be hidden for all the records and it's called fieldheader instead.
Also have a look at the functions under viw and list pages, they have different arguments. The view page has the $values argument in there for you to use.

So I think you might get this to work (set fieldblock to false)only for view or edit when you display a single record
Jane the forum admin is the expert so I would wait for her 2 cents <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=37361&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

K
kjonmyway author 2/2/2009

Thank you so much for taking the time to respond! Although I will definitely wait to get input from Jane, I really appreciate you taking the time to post this - it makes sense.
Thanks again!