Connecting a List Page to a Reports Page

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

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

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

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/

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

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/

Worked perfectly!!! Thank you SO much!

Okay, I promise, I'm almost done! :) 

On the Stallion Listing page:  http://www.superiorequinesires.com/cdb-listing.php

• on the Info link column, can I make it so if no url is entered in the admin, that the word "info" does not show at all?  Right now the word "info" is completely out, but it's still intact on my test page (http://www.superiorequinesires.com/cdb-listing2.php)

ALSO On the Stallion Listing page:  http://www.superiorequinesires.com/cdb-listing.php

Is it possible to only allow users to see this page? The client would like it so only people who have signed up as a member (entered as a user)  can view reports.  I believe at that point, it would be okay if they were able to view the cdb-listing.php page, just not any of the reports (linked from the name and in the 4th column)  Right now "Rotspon" has a test report. 

At any point, members could log in and request new stallions be added to the database (via form). 

ALSO... :) Is there any way to automate the signup process? 

for example:  When someone wants to become a member (user) they fill out the member form (name, email, username, password) and then the admin simply approves or disapproves the member to  be added.

 thank you thank you!!!