unable to pass a value from a cell.

aej1973
aej1973 used Ask the Experts™
on
Hi,

I have developed a application that shows the different events scheduled and the scheduled events are displayed in a calendar view. I have been able to pass the event details to the calendar. I have a link on the events that when I click, opens up a pop up and I can update the event. Well, this works if I just have one event in the cell ( April 16th in events.jpg). The problem comes up when I have multiple events on the same date. The visit_id that gets passed when I click the link is always the last ID in that cell even though the event ID is correctly displayed on the calendar. For eg, any link that I click on April 17 will have an event ID of 107.  How do I correct this issue? Thank you for the help.

A
events.jpg
db.jpg
code-snippet.txt
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I'm not sure how to fix it but I think you need to look at this piece of your code:

foreach($events[$cellDate] as $event)
  {
    // Append additional <div>s
    $calendar .= '<div class="eventDisplay'.$event['visit_status'].'">'.$event['nurse_lastName']."-".$event['type_name'].'-'.$event['visit_id'].'</div></br>';
	 $tempVisit=$event['visit_id'];
  }

Open in new window


You're constantly updating the $tempVisit variable in the foreach loop. A a result at the end of the loop it will always contain the last visit_id from the mysql result.

Try making a unique link for each cell inside the loop:

foreach($events[$cellDate] as $event)
  {
    // Append additional <div>s
    $calendar .= '<div class="eventDisplay'.$event['visit_status'].'">'.$event['nurse_lastName']."-".$event['type_name'].'-'.$event['visit_id'].'</div></br>';
	 $tempLink= "<a href="link_to_with_unique_visit_id_.$event['visit_id']."</a>;
  }

Open in new window


off course you'll have to adapt my code, but I have a feeling this might bring you closer to a solution.

Regards,
dmonkey

Author

Commented:
Thanks dmonkey, but it is still displaying the visit ID as 103 for all event on April 17th. Any suggestions? Thanks.

A
OK really hard to see the exact problem with just a few lines of code but:

Could it be that you are making only one hyperlink across all your divs ?

It seems to me that the table you print out in $output has only one hyperlink and the body of the link (between <a> </a>) contains all your eventDisplay divs (created in $calendar)...
so it would be normal that all your divs point to the same visit_id (namely the last one in your foreach loop)

I think you need to restructure your code a little and generate a link for each event inside of the foreach loop.

dmonkey
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Most Valuable Expert 2011
Top Expert 2016

Commented:
Have you considered using one of the popular frameworks?  This field has been plowed by others before, and most of us who are professional developers do not try to write out own calendar modules any more.  Calendar applications are a "pure science" question that date from the 1980's.  All of that is understood and subsumed into computer science today, in much the same way that electric lights are considered in the design of a home.  It's just "the way it's done," not something to be studied.  

You might want to consider using WordPress, Joomla or Drupal to form the foundation of your online app.  While I realize this does not answer your question about why the existing code does not work, I think that in the larger picture of trying to get an application up and running, you would be well served to build on the work of others and use customization to bridge the gap between the general "framework" solutions and the specific needs of your application.  Just a thought... ~Ray

Author

Commented:
Thanks dmonkeyjazz. Modifying the script as show  below solved my problem.

$calendar .= '<A HREF=editPlannerSchedule.php?cell='.$event['visit_id'].' onClick="return popup(this, \'$cellDate\')"><div class="eventDisplay'.$event['visit_status'].'">'.$event['nurse_lastName']."-".$event['type_name'].'</div></br>';

Regards,
A

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial