This topic is locked

Master Detail relationship

1/18/2008 8:27:42 AM
PHPRunner General questions
N
nicolagrimshaw author

Hello
I've created a database of hotels, including all the important information relating to each property. The master include basic information and I've created a number of detail tables with further information such as information on hotel bars, restaurants, spas and other facilities they may offer, although this will not relate to all properties or we may not have the information listed. Where no information is held, is it possible for the link to the detail not to be displayed? This would make it much easier for the user to navigate. Please see demonstration site Hotel Search At present the only hotel which has any detail information is Capri Palace Hotel & Spa.
Also is there a way to display the detail information on the master view page?
I hope this makes sense? Thanks in advance.

J
Jane 1/21/2008

Hi,
you can do the following:

  • edit link to detail table on the Visual Editor tab --> HTML mode.

    Here is a sample (my changes in Bold):
    {if $row.1detailsfound_value}<A href="DetailTableName_list.php?{$row.1DetailTableName_masterkeys}"

    {if $useAJAX} onmouseover="RollDetailsLink.showPopup(this,'DetailTableName_detailspreview.php'+this.href.substr(this.href.indexOf('?')));" onmouseout="RollDetailsLink.hidePopup();" {/if}>DetailTableName</A>{/if}


  • then add following code to the List page: After record processed event on the Events tab:
    global $conn;

    $str = "select * from DetailTableName where DetailID=".$data["MasterID"];

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

    if ($data = db_fetch_array($rs))

    {

    $row["1detailsfound_value"]=true;

    }

    else

    {

    $row["1detailsfound_value"]=false;

    }

N
nicolagrimshaw author 1/22/2008

Hi Jane,
Thanks for your reply - it's great to know it can be done, although I'ver not quite managed it yet. Will play around and post again with more details if I'm still struggling. I would also be interested to know if it is possible to have links to the 'detail' information from the view page or if there is a way to add the information in a text box?
Thanks again
DKWID

N
nicolagrimshaw author 1/22/2008

Hi
I may be wrong but I think the problem lies in the way I have set up the tables. I think the below is correct?

global $conn;

$str = "select * from _spa where spa-id=".$data["ID"];

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

if ($data = db_fetch_array($rs))

{

$row["1detailsfound_value"]=true;

}

else

{

$row["1detailsfound_value"]=false;

}


But I get an error description > Unknown column 'spa' in 'where clause'

When I try using accommodation name which is both the primary and foreign key (which I though might fix the problem) I get the following error!
I get an error > You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name=Elephant House' at line 1


Any ides? Thanks in advance

A
alang 1/22/2008

I've found its better to put quotes around the value. See http://www.asprunner.com/forums/index.php?...ost&p=24118

R
Rigmantas 2/16/2008

Hi,

I test this example - this is good thing. How about too many details pages? How I can change this script:
global $conn;

$str = "select
from DetailTableName where DetailID=".$data["MasterID"];

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

if ($data = db_fetch_array($rs))

{

$row["1detailsfound_value"]=true;

}

else

{

$row["1detailsfound_value"]=false;

}*
Rimantas

Thanks

J
Jane 2/18/2008

Rimantas,
repeat all actions for each detail links.

L
laonian 2/20/2008

I have tried the above code and it works great. One more question about the preview: Is it possible to select only a few fields from the detail table to display in onmouseover preview, and when you click the link, you will still see the complete detail list page? The reason is you may have e.g. ten fields in your detail table and you list them all. But for master-detail relation preview, only a few fields, e.g. three, are important.

J
Jane 2/21/2008

Hi,
you can do the following:

  1. create custom view of detail table on the Datasource tables tab, setup master-detail relationships for this view also, check three fields on the list page for this view on the Choose fields tab.
  2. then edit detail link on the Visual Editor tab.

    See my changes in Bold:
    <A class=tablelinks2 href="DetailTable_list.php?{$row.1DetailTable_masterkeys}" {if $useAJAX} onmouseover="RollDetailsLink.showPopup(this,'DetailTableView_detailspreview.php'+this.href.substr(this.href.indexOf('?')));" onmouseout="RollDetailsLink.hidePopup();" {/if}>DetailTable</A>



And remove column of links to DetailTableView on the Visual Editor tab.

L
laonian 2/21/2008

Hi,

you can do the following:

  1. create custom view of detail table on the Datasource tables tab, setup master-detail relationships for this view also, check three fields on the list page for this view on the Choose fields tab.
  2. then edit detail link on the Visual Editor tab.

    See my changes in Bold:
    And remove column of links to DetailTableView on the Visual Editor tab.



Jane, your code worked perfectly. Thanks a lot.