Hope my title makes sense once I explain the issue. I have a page that reads MYSQL and creates a DIV for each user. This number of DIVs can be in the hundreds. In each DIV there's user info and such but a fancybox link depending on the DIV's need. So far I have had the DIVs with fancybox links created as such:




localhost/include/_MyStuff.php


PHP Code:
    foreach ($aa as $value)
    {
       ...
a bunch of other code that is pointless to this issue...
                 <
div class='msd_linksrow'><class=\"fancybox\" href=\"#message_".$userinfo->userid."\" >Message</a>&nbsp;</div>
           require'../include/loader.php';
       ...a bunch of other code that is pointless to this issue...
    } 




This creates a

localhost/include/loader.php



Code:
            <div id="message_<?php echo $userinfo->userid; ?>" style="width:400px;display: none;">
                <p>Message <?php echo $userinfo->username; ?></p>
            </div>
for each user and works perfectly. BUT the problem is that when I run the entire script which creates 3 other similar fancyboxes for each user it runs the loader.php far too much. If, for example I have 5 users, the foreach will loop 5 times which will create





Code:
            <div id="message_1"style="width:400px;display: none;">
                <p>Message user1<p>
            </div>
            <div id="message_2"style="width:400px;display: none;">
                <p>Message user2<p>
            </div>
            <div id="message_3"style="width:400px;display: none;">
                <p>Message user3<p>
            </div>
            <div id="message_4"style="width:400px;display: none;">
                <p>Message user4<p>
            </div>
            <div id="message_5"style="width:400px;display: none;">
                <p>Message user5<p>
            </div>




Again, this works well but can slow my site down depending on how many users. The really big problem is trying to change '<p>Message user#<p>' to a fancybox for with its own javascripts. I have been replacing '<p>Message user#<p>' with '<?php require'form.form.php'; ?>




localhost/form/form.php



PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Contact Form Using CSS3 and FancyBox 2 from iAPDesign</title>

</head>

<body>
<?php echo $who?>
<div id="show_our_contact_form">
<h3>Send us Message / Feedback / Comment / Suggestions!</h3>
<p><span class="errormsg"></span></p>

<label for="name">* Name </label>
<p>
<input name="fname" type="text" id="name" minlength="4" maxlength="15" required/>
</p>

<label for="email">* Email </label>
<p>
<input name="email" type="text" id="email" required/>
</p>

<label for="message">* Message</label>
<p>

<textarea name="messages" id="message" minlength="2" required></textarea>

</p>
<p>
<input value="Send Message" type="button" id="send_form"/> 
<br/>
<!-- Add our Jquery 1.8.2 -->
<script type="text/javascript" src="form/lib/jquery.validate.min.js"></script>
<!-- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> WILL USE IT LATER
<!-- Add Fancybobx JS File -->
<script type="text/javascript" src="form/lib/jquery.fancybox.js?v=2.1.3"></script>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=110994505629056";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<script type="text/javascript">

 $(document).ready(function(){

  $("#contact_us").fancybox({
   type:"inline",
   closeBtn :true
  });
  
 });
 $("#send_form").click(function(){ 
  
  var name  = $("#name").val();
  var email  = $("#email").val();
  var message = $("#message").val();
  
   if( (name == "") || (email == "") || (message == "")){
    $(".errormsg").html(" * All fields Required").fadeIn("Slow").fadeOut(3000);
   }else if(!isValidEmailAddress(email)){
    $(".errormsg").html(" * Invalid Email").fadeIn("Slow").fadeOut(3000);
   } else{
    $(".errormsg").fadeOut();
    $.ajax({
     type :'POST',
     url  :'form/php/process.php',
     data :{ 'name'   : name,
        'email'  : email,
        'message': message,
        },
     beforeSend: function(){
      $("#show_our_contact_form").empty().html("<h3>Sending your Message to our Awesome Boss! Please wait . . . </h3>");
     },
     error:function(){
      alert("Something went wrong!");
     },
     success:function(returnData){
      $("#show_our_contact_form").empty().html("<h3>Your Message Successfully Delivered! <br/> Thank you</h3>");
      
     }
    });
   }
   
 });
 
 var isValidEmailAddress = function(email_add) {
  var pattern = new RegExp(/^[+a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i);
  return pattern.test(email_add);
 };
 
</script>


</body>
</html>
Having form.php run for each user does work but extremely slows my site down.

I have tried to change the hyperlink to include the userinfo->userid like '<a class=\"fancybox\" href=\"userid=$userinfo->userid#message\" >Message</a>' which fails.




What I'm hoping for is a way to create a single DIV id'd as 'message' where I can send the variable '$userinfo->userid' so that the Message DIV runs the form once no matter the userid but will have the userid variable so I know who the form is from.