Hyperlinking to other table data

11 posts by 4 authors in: Forums > CMS Builder
Last Post: November 24, 2008   (RSS)

By gethudson - May 11, 2008

Hello there. I have looked to an answer for the following and I cannot find it in the knowledgebase. I suspect that this is probably because I am new to PHP, so please bear with me. I hope you can help.

I have two sections/tables. The first is called ‘issue’ and has one text field called ‘issuemonth’ into which a year and month are typed in the format ‘yyyymm’. This list viewer appears as I want it:
Issue - List Page Viewer
Issue for: 200806
Issue for: 200805

The second section/table is called ‘page’ and has two fields: a text field called ‘page_number’ into which a page number (001, 002, …) is typed, and ‘assign_issue’ which uses a picklist generated from the ‘issuemonth’ field in the ‘issue’ table. The list viewer page appears like this:
Page - List Page Viewer
Issue: 200806 - Page Number: 001 - Link: pageDetail.php?8
Issue: 200806 - Page Number: 002 - Link: pageDetail.php?6
Issue: 200805 - Page Number: 001 - Link: pageDetail.php?1
Issue: 200805 - Page Number: 002 - Link: pageDetail.php?2

What I am struggling to achieve is that I want to be able to click on a link in the Issue - List Page Viewer page and be sent to something that looked like the Page - List Page Viewer page, but only showing records that related to the ‘issuemonth’ that had been clicked.

Code – top of Issue - List Page Viewer:
list($issueRecords, $issueDetails) = getRecords(array(
'tableName' => 'issue',
));

Code – body of Issue - List Page Viewer:
<?php foreach ($issueRecords as $issueRecord): ?>
Issue for: <a href="<?php echo $issueRecord['_link'] ?>"><?php echo $issueRecord['issuemonth'] ?></a>
<hr/>
<?php endforeach; ?>

Code – top of Page - List Page Viewer:
list($pageRecords, $pageDetails) = getRecords(array(
'tableName' => 'page',
));

Code – body of Page - List Page Viewer:
<?php foreach ($pageRecords as $pageRecord): ?>
Issue: <?php echo $pageRecord['assign_issue'] ?>&nbsp;-&nbsp; Page Number: <?php echo $pageRecord['page_number'] ?>&nbsp;-&nbsp;Link: <a href="<?php echo $pageRecord['_link'] ?>"><?php echo $pageRecord['_link'] ?></a>

Thanks for any assistance in advance, George

Re: [Dave] Hyperlinking to other table data

By gethudson - May 12, 2008 - edited: May 12, 2008

Thank you Dave. It's easy when you nkow how! [;)] Yes, I get it. All pages are searchable, therefore you just append the correct parameter then copy & paste that into your code and add on the PHP bit that adds on that parameter. It can't all be that easy though, I'm sure.

Just for the record in case it helps any other newbie, then here is my final code:

<?php foreach ($issueRecords as $issueRecord): ?>
Issue for: <a href="pageList.php?assign_issue=<?php echo $issueRecord['issuemonth'] ?>">
<?php echo $issueRecord['issuemonth'] ?></a>
<hr/>
<?php endforeach; ?>

Re: [gethudson] Hyperlinking to other table data

By Dave - May 12, 2008

Glad to hear it's working, and thanks for posting your code! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hyperlinking to other table data

By Janet - July 21, 2008

I've got a similar question and hope you can help.

I'm trying to link one record to another within the same database ("faculty_member"). In this case, it's directory listing where professors and students can enter their information. I've added an extra field where students can enter the name of their advising professor. I made this field ("major_professor") a list field using the same database ("faculty_member") to populate the list. I used "num" as one list field option and "lname" as the another (just in case there are two professors with the same last name.)

I can't figure out how to filter the search so that the value of "major_professor" links to that professors profile page.


This is what the code looks like so far:

<?php
$type = @$_GET['faculty_directory'];
if ($type == 'Postdoctoral Associates'):
?>

<h2> <?php echo $facultyDirectory ?> </h2>
<?php foreach ($listRows as $record): ?>
<div class="directory-listing">

<h5> <?php echo $record['fname'] ?> <?php echo $record['lname'] ?> </h5> // gets the name of the student

<p class="locale">
<a href="facultyMember.php?<?php echo $record['major_professor] ?>"><?php echo $record['major_professor] ?></a> //this is the linking statement where the name of the major professor links to his/her profile page.

<p class="contact"> <a href="mailto:<?php echo $record['email'] ?>"> <?php echo $record['email'] ?> </a> <br />
<?php echo $record['phone_number'] ?> (voice)<br />
<?php echo $record['fax_number'] ?> (fax) </p>

</div>
<?php endforeach ?>
<?php endif ?>

I hope my explanation make sense.

Jan

Re: [Janet] Hyperlinking to other table data

By Dave - July 21, 2008

Hi Janet,

So is there a field in the 'faculty_member' section that will have the same value as $record['major_professor]?

If so you'd use a special url to search on that field like this:

facultyMember.php?lname_keyword=<?php echo $record['major_professor] ?>

You can read about the search features here:
http://www.interactivetools.com/docs/cmsbuilder/viewer_search.html

Hope that helps, let me know if you need more help with that.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Hyperlinking to other table data

By Janet - July 21, 2008

I think it would work... except the link pulls up another unrelated entry that contains "lname" in the text. I tried using "num" as a list field option which would be a more exact way to locate the entry but my attempts weren't successful.

Jan

Re: [Janet] Hyperlinking to other table data

By Janet - July 21, 2008

Dave -

We're going in a different direction for this solution. Don't trouble yourself. I'm going to add a couple of fields which we'll enter manually. A couple of the faculty are listed twice and my content editor doesn't know which one to select from the list menu. Thanks anyway!

Jan

Re: [Janet] Hyperlinking to other table data

By Dave - July 22, 2008

Ok, no problem. Let me know if you need anything else.
Dave Edis - Senior Developer
interactivetools.com

Hyperlinking to other table data : I DONT UNDERSTAND

Hello, i think my problem is similat.
I have a section editor call "Categories".
I have another section editor call "product".
Product is compose by:
- category (this is a list, the options are from the other section editor upper "Categories"
- title
- content

Here is what i want to do : A page with all the "Categories" entry listed. When i click on one "Categorie" i want to display a page which will list the "products" of the Categorie.
In this page i want to be able to also display the name of the categorie where my product are listed