Connecting a List Page to a Reports Page

13 posts by 3 authors in: Forums > CMS Builder
Last Post: September 30, 2013   (RSS)

By csdesign - September 3, 2013

Hello!
I need some help linking up some elements in cmsb.

I have a Stallion Database that the owner will list the stallions, then she signs up new users to report on the conception results they had with the stallions. So what I'm trying to do is link up the Stallion List with the Reports written by users.


This is the Stallion List: (php page attached)
http://www.superiorequinesires.com/cdb-listing.php

(Notice that "# of reports" is blank and no link to reports for each stallion)


This is the Stallion Reports page (all reports) (php page attached)
http://www.superiorequinesires.com/cdb-stallion-reports.php

From the stallion list page, I want to link the stallion name to a list page of THAT individual stallion's reports only.

AND...

I would also like to have the number of reports that have been generated by various users to show up in the # of reports table on the Stallion List.


Since I am spilling on my wish list...
On the Stallion Reports page - at the bottom of each report is "Reported by user #X". Can I have that link to ALL reports by user #X ?


Thanks!!! Tina

By csdesign - September 3, 2013

Almost forgot, in addition... Can I manually add a csv list (stallion name, stallion breed) instead of entering them manually into the admin? 

By gregThomas - September 4, 2013

Hi Tina, 

How are the stallions linked to the reports? Is it via a list field that uses this system:

http://www.interactivetools.com/kb/article.php?Populate-a-list-field-from-another-section-15

I think you probably need to add a where statement to your cdb-stallion-reports.php file that filters on a particular stallions num value, and then pass a horses num value into the reports page on cdb-listing.php, you could pass the horses num value like this on your cdb-listing.php page:

                  <?php foreach ($cdb_stallionsRecords as $record): ?>
                    <table width="100%" border="0" cellspacing="2" cellpadding="3">
                      <tr>
                        <td width="39%" height="30" align="left" valign="middle" bgcolor="#F5EBD2" class="content01bold"><?php echo htmlencode($record['title']) ?></td>
                        <td width="28%" align="left" valign="middle" bgcolor="#F5EBD2" class="content"><?php echo htmlencode($record['breed']) ?></td>
                        <td width="16%" align="left" valign="middle" bgcolor="#F5EBD2" class="content"><a href="<?php echo htmlencode($record['ses_url']) ?>" class="captions">Info</a></td>
                        <td width="17%" align="left" valign="middle" bgcolor="#F5EBD2" class="content"><a href="cdb-stallion-report.php?num=<?php echo $record['num']; ?>" >Report</a></td>
                      </tr>
                    </table>
                  <?php endforeach ?>

To add a count of the total records on your reports page you just need to use the count function on cdb_stallion_reviewsRecords:

count($cdb_stallion_reviewsRecords);

The easiest way to show all of a users reports might be to have a user profile page, where you click on a link and it takes you to a users profile page and shows all of the reviews they have created.

If you would like us to create this system for you, feel free to send an e-mail to consulting@interactivetools.com, and we can give you an estimate of the cost.

The easiest way to import the reports as a CSV might be to use the CSV import plugin, you can read more about it here: 

http://www.interactivetools.com/add-ons/detail.php?CSV-Import-1041

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By csdesign - September 5, 2013

Hi Greg, thank you for the reply! 

The Stallion List and the Stallion Reports are connected by Title (Stallion Name) which is populated via a list field from another section.

I added the code to the stallion List page: http://www.superiorequinesires.com/cdb-listing.php

Now, when you click  on Barrosa's "Report" link it goes to: 

http://www.superiorequinesires.com/cdb-stallion-reports.php?num=2

but all of the reports are still there, not just Barroso's, which is record number 2. 

I tried changing it to "title" instead of "num" but got the same results - it showed reports for all stallions. 


I added  "count($cdb_stallion_reviewsRecords);" to the top of the cdb_stallion_reviewsRecords.  I want the reviews count number to show up on the Stallion listing page instead of the word "report"...   so I'm a little confused on how to connect those two. 


All the users do have a profile page - which we were going to keep private, but I suppose I could just hide the info I don't want to be seen. :) 


Thank you again for your help!!! 

By Jason - September 5, 2013

Hi,

What you need to do is restrict your getRecords call on the cdb-stallion-reports.php page to only return records based on a title passed through the URL.

So, for example,  the url would look like this:

http://www.superiorequinesires.com/cdb-stallion-reports.php?title=Barrosa

Then, you can change your getRecords call like this:


 // load records from 'cdb_stallion_reviews'
  list($cdb_stallion_reviewsRecords, $cdb_stallion_reviewsMetaData) = getRecords(array(
    'tableName'   => 'cdb_stallion_reviews',
    'perPage'     => '50',
    'where'       => "title = '".mysql_escape(@$_REQUEST['title'])."'",
    'loadUploads' => true,
    'allowSearch' => false,
  ));



This will only return report records that have the same title value as the title in the URL.

Give this a try and let me know if you run into any issues.

Thanks!

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By csdesign - September 12, 2013

It worked!! I had to change the settings on my list but then it worked :) Thank you! 

By csdesign - September 17, 2013

Wow... I keep sending a "reply" but it doesn't post. Weird.  Let's try this again! 

Per the instructions, I tried adding this to the cdb-listing.php page  but I just get an error on that line. I removed it because it needed to go live and created a dummy page (attached): 
http://www.superiorequinesires.com/cdb-listing2.php

thinking I had the wrong page,  I also tried it on the cdb-stallion-reports.php page (attached) - no error there, but that's not the page I need the count to show up on. I guess I'm confused. 

To add a count of the total records on your reports page you just need to use the count function on cdb_stallion_reviewsRecords:

count($cdb_stallion_reviewsRecords);

Here's what I'm trying to accomplish: 

• In the reports column, there is a number of reports for that stallion (ie:  20 reports). I have the link down... just need the count to show up. 

• If there are no reports, then I need it to list it as "0 reports". I'm assuming the count feature will do that though. 

• Also, on the Info link, can I make it so if no url is entered, that the word "info" does not show at all? 

Thanks!! Tina

By Jason - September 18, 2013

Hi Tina,

Glad you got the post to work! :)

I took a look and the issue is that on your list page, we are not creating a variable called $cb_stallion_reviewsRecords.  The other issue is that we are outputting multiple horses, each with a different report count.  The best way to accomplish this is to use the mysql_count() function inside our foreach loop.  This will allow us to get a report count on the fly as we're outputting our horse information.

Give this a try:

<?php foreach ($cdb_stallionsRecords as $record): ?>
  <?php  $reportCount = mysql_count("cdb_stallion_reviews", "title =  '".mysql_escape($record['title'])."'"); ?>

  <table width="100%" border="0" cellspacing="2" cellpadding="3">
    <tr>
      <td width="39%" height="30" align="left" valign="middle" bgcolor="#F5EBD2" class="content"><a href="cdb-stallion-reports.php?title=<?php echo $record['title']; ?>" ><?php echo htmlencode($record['title']) ?></a></td>
      <td width="28%" align="left" valign="middle" bgcolor="#F5EBD2" class="content"><?php echo htmlencode($record['breed']) ?></td>
      <td width="16%" align="left" valign="middle" bgcolor="#F5EBD2" class="content"><a href="<?php echo htmlencode($record['ses_url']) ?>" class="captions">Info</a></td>
      <td width="17%" align="left" valign="middle" bgcolor="#F5EBD2" class="content">
                      
        <a href="cdb-stallion-reports.php?title=<?php echo $record['title']; ?>" > <?php echo $reportCount;?> Reports</a>
      </td>
    </tr>
  </table>
  
<?php endforeach ?>

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By csdesign - September 25, 2013

Worked perfectly!!! Thank you SO much!