This topic is locked

Hide field picture /link if detail table is empty.

6/17/2008 11:04:00 AM
PHPRunner General questions
M
mmponline author

I have a master detail relationship. The detail table link (or picture as I have it setup) should only show when the detail page contains info for the specific record.
How can I achieve this?
My code on view page:

<TD width=40><A

href="GalleryUser_list.php?{$GalleryUser_masterkeys}"><IMG

alt="Gallery"

src="images/gallery.jpg"

border=0></A></TD>


In event - Before display:

$smarty->assign("GalleryUser_masterkeys","mastertable=ListingUser&masterkey1=".$values["ListID"]);
M
mmponline author 6/18/2008

Any help, please!

J
Jane 6/19/2008

Stephan,
edit your detail link on the Visual Editor tab:

{if $row.detaillink}

<TD width=40><A

href="GalleryUser_list.php?{$GalleryUser_masterkeys}"><IMG

alt="Gallery"

src="images/gallery.jpg"

border=0></A></TD>

{/if}


Then add following code to the List page: After record processed event:

global $conn;

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

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

if (!$data = db_fetch_array($rs))

$row["detaillink"] = 0;

else

$row["detaillink"] = 1;

M
mmponline author 6/19/2008

Jane

I forgot to say that this link lies on the view page (not list page).

I've changed the code in the following way and get no errors. The link is not showing now at all, however, whether the details table has info or not.

{if $row.gallerylink}

<TD>

<P align=center>&nbsp;<IMG alt=Gallery

src="images/gallery.jpg"

border=0></P></TD>{/if}


Then added this code to my View Page: Before DisplayEvent: (Had to change to $values of course

global $conn;

$str = "select * from Gallery where OtherID=".$values["ListID"];

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

if (!$values = db_fetch_array($rs))

$row["gallerylink"] = 0;

else

$row["gallerylink"] = 1;


Gallery= Details Table

OtherID = Related ID to Master Table (Also tried Details tabel's ID)

ListID= Master table's ID
Thanks for your help with this...

M
mmponline author 6/20/2008

Still need help on this code...

J
Jane 6/20/2008

Stephan,
this code won't work on teh view page. There is no any $row variable.

Here is the correct code:

{if $gallerylink}

<TD>

<P align=center>&nbsp;<IMG alt=Gallery

src="images/gallery.jpg"

border=0></P></TD>{/if}


global $conn;

$str = "select * from Gallery where OtherID=".$values["ListID"];

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

if (!$values = db_fetch_array($rs))

$smarty->assign("gallerylink",0);

else

$smarty->assign("gallerylink",1);

M
mmponline author 6/22/2008

Jane
Thios works fine, thanks. I now have one mre further need that I'm struggling with.
I need to repeat this code on the page to show /hide other links. I've named the next ones maplink, specialslink, etc.
I need th add the events for these ones as well, but with my tries get an error code. What am I doing wrong?

My code:

global $conn;

$str = "select * from Gallery where OtherID=".$values["ListID"];

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

if (!$values = db_fetch_array($rs))

$smarty->assign("gallerylink",0);

else

$smarty->assign("gallerylink",1);
global $conn;

$str = "select * from Map where OtherID=".$values["ListID"];

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

if (!$values = db_fetch_array($rs))

$smarty->assign("maplink",0);

else

$smarty->assign("maplink",1);
J
Jane 6/23/2008

Stephan,
you can looks good.

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.