This topic is locked

Conditional Field Heading

10/30/2007 10:07:29 AM
PHPRunner General questions
O
osluk author

I have a project where wine tasting notes may or may not be present.
With tasting notes:

http://www.bordeauxreport.com/db-2007/view...php?editid1=211
No tasting notes:

http://www.bordeauxreport.com/db-2007/view...php?editid1=132
To stop it looking scrappy and incompete I want to only have the entry 'Tasting Notes:' dispalyed if there is content.
If I added a field (to allow it to be used for different purposes) which contained 'Tasting Notes:' could I then disply this only if the field 'Tasting notes' was not null.
Cheers Chris

J
Jane 10/31/2007

Chris,
you can do it editing this page in the HTML mode on the Visual Editor tab.

Find this code:

<TR>

...

<TD>Tasting Notes:</TD>

...

</tr>

and replace it with this one:

{if $show_TastingNotes}

<TR>

...

<TD>Tasting Notes:</TD>

...

</tr>

{/if}



where TastingNotes is your actual field name.

O
osluk author 11/2/2007

Jane that is perfect
Many Thanks

M
mmponline 11/3/2007

Further expantion:
I want the view hyperlink (on the list page to the view page) to only display if the a specific field contains info in the view page.

Eg.

List page has "title" and "shortdescription" as fields and contains a link to view page where the "longdescription" field is displayed.
The view link must only show if the "longdescription" field on the view page contains info. If there is no info in the description field (the view link should not display on the list page.
Appreciate your help!

J
Jane 11/6/2007

Stephan,
here is a sample code:

global $data,$conn;

$str = "select longdescription from TableName where title='".$data["title"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

if ($data["longdescription"])

$value = "<a href=\"tablename_view.php?editid1=".$data["ID"]."\">view page</a>";

C
chaz 11/6/2007

how how do u do this for the mastr-slave relationship listing......there is a link to the foreign table but how do u allow a link ONLY where there is data in the foreign key
Also where do u edit the html of javascript popup???

J
Jane 11/7/2007

Hi,
you can do the following:

  1. edit SQL query on the Edit SQL query tab. Here is a sample:

    select FieldName1,

    FieldName2,

    ...

    ForeignKeyField,

    ForeignKeyField as link,

    ...

    From MasterTableName


  2. check off link field on the list page only,


  3. setup link field as Custom on the "View as" settings dialog on the Visual Editor tab.

    Here is a sample code:

    global $conn;

    $str = "select count(*) from DetailTableName where DetailForeignKey=".$value;

    $rs = db_query($str,$conn);

    if ($data = db_fetch_numarray($rs))

    $links = "<a href=\"DetailTableName_list.php?mastertable=MasterTableName&masterkey1=".$value."\">DetailTableName</a>";

    else

    $links = "";

    $value = $links;





where DetailTableName and MasterTableName are your actual table names, DetailForeignKey and ForeignKeyField are your actual field names.