Page 1 of 1

Sorting the Data

Posted: Wed Feb 08, 2012 12:28 am
by ryojinaiseki
Is there any way that I can sort out just the date only? Here's the code:

Code: Select all

<?php
    session_start();
    
    include "classes/connect.class.php";
    include "classes/library.class.php";
    include "classes/paging.class.php";

    $con = new connect;
    if(!$con->connectDatabase())
        die("Unable to connect to the server. Please try again.");
    
    //SET DATABASE ENCODING TO UTF-8 FOR SPECIAL CHARACTERS TO WORK FINE
    mysql_query('set NAMES utf8') or die(mysql_error());

    $page = "contacts.php";
    if(!isset($_GET['start'])){
	$start = 0;
    }else{
	$start = $_GET['start'];
    }

    if(strlen($start) > 0 and !is_numeric($start)){
	die("Data Error");
    }

    //CATEGORY, TYPE, EVENT, DATE, AGENCY SESSION
    $category = trim($_GET['category']);
    $type = trim($_GET['type']);
    $eventId = trim($_GET['eventId']);
    $dateId = trim($_GET['dateId']);
    $agencyId = trim($_GET['agencyId']);
    $sessionId = trim($_GET['sessionId']);
    $institution = trim($_GET['institution']);

    $_SESSION['dateId'] = $dateId;
    $_SESSION['eventId'] = $eventId;
    $_SESSION['agencyId'] = $agencyId;
    $_SESSION['sessionId'] = $sessionId;
    $_SESSION['display'] = trim($_GET['display']);

    $display = "<b>Display Criteria:</b> ". stripslashes(trim($_GET['display']));
    //INVITED, CONFIRMED, ATTENDED
    $invited = trim($_GET['invited']);
    $confirmed = trim($_GET['confirmed']);
    $attended = trim($_GET['attended']);
    //SEARCH KEY
    $searchkey = trim($_GET['searchkey']);

    //CREATE PAGING INSTANCE
    $limit = 10;
    $paging = new paging($start, $page, $limit);
    $eu = $paging->eu;
    $limit = $paging->limit;
    if(isset($_GET['sq'])){
	$sql = urldecode($_GET['sq']); //SQL FOR PAGING
	$sql = stripslashes($_GET['sq']);
	$sql = explode("LIMIT", $sql);
	$sql = $sql[0]." LIMIT ". $start. ", ". $limit;
    }else{
	$sql = buildQuery($eu, $limit, $searchkey, $category, $type, $dateId, $eventId, $agencyId, $sessionId, $institutionId, $invited, $confirmed, $attended, $display, $institution);
    }

    $paging->sq = $sql;

    $sqlPaging = explode("ORDER BY", $sql);

    $_SESSION['ids'] = $sqlPaging[0];

    $paging->getRowsNumber($sqlPaging[0]);
    $nume = $paging->nume;
    $paging->nume = $nume;
    //$start = $paging->start;
    $paging->printPagelinks($paging->sq, $paging->nume, $_SESSION["cr"]);
    if(isset($_SESSION['user']) && isset($_SESSION['login'])){
        viewContacts($sql, $start, $nume);
    }else{
        viewLimitedContacts($sql, $start, $nume);
    }

    $paging->printPagelinks($paging->sq, $paging->nume, $_SESSION["cr"]);

function buildQuery($eu, $limit, $searchkey, $category, $type, $dateId, $eventId, $agencyId, $sessionId, $institutionId, $invited, $confirmed, $attended, $display, $institution=null){
    $c = 0;
    if($category != "" || $type!= "" || $dateId != "" || $eventId != "" || $agencyId != "" || $sessionId != "" || $institution != "" || $invited != "" || $confirmed != "" || $attended != "" || $searchkey != ""){
        $arr = array("category"=>$category, "type"=>$type, "date"=>$dateId, "event"=>$eventId, "agency"=>$agencyId, "session"=>$sessionId, "institution"=>$institution, "invited"=>$invited, "confirmed"=>$confirmed, "attended"=>$attended, "searchkey"=>$searchkey);
        foreach($arr as $thisKey=>$thisValue){
            if($thisValue != ""){
                $func = "getIdsFor".ucwords($thisKey);
                
                if($thisKey == "invited" || $thisKey == "confirmed" || $thisKey == "attended")
                    $theIds = $func($dateId, $eventId, $sessionId, $thisValue, $eu, $limit);
                elseif($thisKey == "agency"){
                    $theIds = $func($dateId, $eventId, $thisValue, $eu, $limit);
                }elseif($thisKey == "institution"){
					$theIds = $func($institution, $eu, $limit);
				}else
                    $theIds = $func($thisValue, $eu, $limit);
				
                if(sizeof($theIds) > 0){
                    $theIdsArray[sizeof($theIdsArray)] = $theIds;
                }else{
                    $theIdsArray[sizeof($theIdsArray)] = array(0 => mt_rand());
                }
                ++$c;
            }
        }

        if(sizeof($theIdsArray) == 1){
            $resultArr = $theIdsArray[0];
        }elseif(sizeof($theIdsArray) == 2){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1]);
        }elseif(sizeof($theIdsArray) == 3){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2]);
        }elseif(sizeof($theIdsArray) == 4){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3]);
        }elseif(sizeof($theIdsArray) == 5){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3],$theIdsArray[4]);
        }elseif(sizeof($theIdsArray) == 6){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3],$theIdsArray[4],$theIdsArray[5]);
        }elseif(sizeof($theIdsArray) == 7){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3],$theIdsArray[4],$theIdsArray[5],$theIdsArray[6]);
        }elseif(sizeof($theIdsArray) == 8){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3],$theIdsArray[4],$theIdsArray[5],$theIdsArray[6],$theIdsArray[7]);
        }elseif(sizeof($theIdsArray) == 9){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3],$theIdsArray[4],$theIdsArray[5],$theIdsArray[6],$theIdsArray[7],$theIdsArray[8]);
        }elseif(sizeof($theIdsArray) == 10){
            $resultArr = array_intersect($theIdsArray[0],$theIdsArray[1],$theIdsArray[2],$theIdsArray[3],$theIdsArray[4],$theIdsArray[5],$theIdsArray[6],$theIdsArray[7],$theIdsArray[8],$theIdsArray[9]);
        }

        if(empty($resultArr)){
            $sql = "SELECT id FROM contacts WHERE id IN (-1)";
        }else{
            $sql = "SELECT id FROM contacts WHERE id IN (";
            $ids = "";
            $cnt = 0;
            foreach($resultArr as $k=>$v){
                $ids = $ids.$v;
                if($cnt < sizeof($resultArr)-1){
                    $ids = $ids.", ";
                }
                
                ++$cnt;
            }
            
            $ids = $ids.") ORDER BY id DESC LIMIT ".$eu.", ".$limit;
            $sql = $sql.$ids;
        }
    }else{
        $sql = "SELECT id FROM contacts ORDER BY id DESC LIMIT ".$eu.", ".$limit;
        $display = $display." All";
    }

    $_SESSION["cr"] = $display;
    $_SESSION['ids'] = $sql;
    return $sql;
}

function getIdsForSearchkey($searchkey, $eu, $limit)
{
	$sql = "SELECT id FROM contacts WHERE display_name LIKE '%".$searchkey."%'";			   
	$result = mysql_query($sql) or die(mysql_error());
	while($row = mysql_fetch_array($result)){
		$contactId = $row['id'];
		$contactIdArr[sizeof($contactIdArr)] = $contactId;
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
						$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForCategory($category, $eu, $limit)
{
	$s = "SELECT id FROM institutions WHERE category LIKE '".$category."'";
	$result = mysql_query($s) or die(mysql_error());
	while($row = mysql_fetch_array($result)){
		$institutionId = $row['id'];
		$sql = "SELECT contact_id FROM contacts_institutions WHERE institution_id = '".$institutionId."'";
		$r = mysql_query($sql) or die(mysql_error());	
		while($row = mysql_fetch_array($r)){
			$contactId = $row['contact_id'];
			if(sizeof($contactIdArr) == 0){
				$contactIdArr[0] = $contactId;
			}else{
				foreach($contactIdArr as $key=>$val){
					if($contactId == $contactIdArr[$key]){
						break;
					}else{
						if($contactId != ""){
							if($key == sizeof($contactIdArr)-1){
								$contactIdArr[sizeof($contactIdArr)] = $contactId;
							}
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForType($type, $eu, $limit)
{
	$typeObj = new library;	
	$where = " type='".$type."'";
	$result = $typeObj->getFields("id, institution", "institutions", $where);
	while($row = mysql_fetch_array($result)){
		$institutionId = $row['id'];
		$where = " institution_id='".$institutionId."'";
		$r = $typeObj->getFields("contact_id", "contacts_institutions", $where);
		while($row = mysql_fetch_array($r)){
			$contactId = $row['contact_id'];
		
			if(sizeof($contactIdArr) == 0){
				$contactIdArr[0] = $contactId;
			}else{
				foreach($contactIdArr as $key=>$val){
					if($contactId == $contactIdArr[$key]){
						break;
					}else{
						//if($contactId != ""){
							if($key == sizeof($contactIdArr)-1){
								$contactIdArr[sizeof($contactIdArr)] = $contactId;
							}
						//}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForDate($dateId, $eu, $limit)
{
	$dateObj = new library;	
	$where = " date_id='".$dateId."' AND";
	$where .= " (invited='1' OR confirmed='1' OR attended='1')";
	$r = $dateObj->getFields("contact_id", "contacts_events_dates", $where);
	while($row = mysql_fetch_array($r)){
		$contactId = $row['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForEvent($eventId, $eu, $limit)
{
	$thisEvent = new library;	
	$where = "event_id='".$eventId."' AND";
	$where .= "(invited='1' OR confirmed='1' OR attended='1')";
	$r = $thisEvent->getFields("contact_id", "contacts_events_dates", $where);
	while($row = mysql_fetch_array($r)){
		$contactId = $row['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForAgency($dateId, $eventId, $agencyId, $eu, $limit)
{
	$thisAgency = new library;
	$where = " agency_id='".$agencyId."' AND date_id='".$dateId."' AND event_id='".$eventId."'";
	$r = $thisAgency->getFields("contact_id", "contacts_events_agencies", $where);
	while($row = mysql_fetch_array($r)){
		$contactId = $row['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForSession($sessionId, $eu, $limit)
{
	$thisSession = new library;	
	$where = " session_id='".$sessionId."'";
	$where .= " AND (invited='1' OR confirmed='1' OR attended='1')";
	$r = $thisSession->getFields("contact_id", "contacts_events_dates", $where);
	while($row = mysql_fetch_array($r)){
		$contactId = $row['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForInstitution($institution, $eu, $limit)
{
	//$sql = "DELETE FROM contacts_events_dates WHERE contact_id NOT IN (SELECT id FROM contacts)";
	$thisInstitution = new library;	
	/*$where = "institution = \"$institution\"";
	$r = $thisInstitution->getFields("id", "institutions", $where);*/
	$sql ="SELECT contact_id FROM contacts_institutions WHERE institution_id IN (SELECT id FROM institutions WHERE institution LIKE \"$institution\")";
	$r1 = mysql_query($sql) or die(mysql_error());
	while($row = mysql_fetch_array($r1)){
		$contactIdArr[sizeof($contactIdArr)] = $row['contact_id'];	
	}
	//$where = "institution_id IN ($r)";
	//$r1 = $thisInstitution->getFields("contact_id", "contacts_institutions", $where);
	//print_r($r1);	
	/*$where = " institution_id='".$institutionId."'";
	$r = $thisInstitution->getFields("contact_id", "contacts_institutions", $where);
	while($row = mysql_fetch_array($r)){
		$contactId = $row['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}*/
	return $contactIdArr;
}

function getIdsForInvited($dateId, $eventId, $sessionId, $invited, $eu, $limit)
{
	$invite = new library;
	if($sessionId != "")
		$where = " date_id='".$dateId."' AND event_id='".$eventId."' AND session_id='".$sessionId."' AND invited='".$invited."'";
	else
		$where = " date_id='".$dateId."' AND event_id='".$eventId."' AND invited='".$invited."'";
	$r = $invite->getFields("contact_id", "contacts_events_dates", $where);
	while($contactIdRow = mysql_fetch_array($r)){
		$contactId = $contactIdRow['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForConfirmed($dateId, $eventId, $sessionId, $confirmed, $eu, $limit)
{
	$invite = new library;
	if($sessionId != "")
		$where = " date_id='".$dateId."' AND event_id='".$eventId."' AND session_id='".$sessionId."' AND confirmed='".$confirmed."'";
	else
		$where = " date_id='".$dateId."' AND event_id='".$eventId."' AND confirmed='".$confirmed."'";
	
	$r = $invite->getFields("contact_id", "contacts_events_dates", $where);
	while($contactIdRow = mysql_fetch_array($r)){
		$contactId = $contactIdRow['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function getIdsForAttended($dateId, $eventId, $sessionId, $attended, $eu, $limit)
{
	$invite = new library;
	if($sessionId != "")
		$where = " date_id='".$dateId."' AND event_id='".$eventId."' AND session_id='".$sessionId."' AND attended='".$attended."'";
	else
		$where = " date_id='".$dateId."' AND event_id='".$eventId."' AND attended='".$attended."'";
	$r = $invite->getFields("contact_id", "contacts_events_dates", $where);
	while($contactIdRow = mysql_fetch_array($r)){
		$contactId = $contactIdRow['contact_id'];
		if(sizeof($contactIdArr) == 0){
			$contactIdArr[0] = $contactId;
		}else{
			foreach($contactIdArr as $key=>$val){
				if($contactId == $contactIdArr[$key]){
					break;
				}else{
					if($contactId != ""){
						if($key == sizeof($contactIdArr)-1){
							$contactIdArr[sizeof($contactIdArr)] = $contactId;
						}
					}
				}
			}
		}
	}
	return $contactIdArr;
}

function viewContacts($sql, $start, $nume){
    $data = new library; ?>
    <table style='width: 100%; padding: 0px;background: #fff; border: solid 0px #ccc;'>
        <!-- <thead style="background: #eef3f7; color: #666; font-weight: bold; width: 5%; font-size:14px; text-align: center;">-->
	<tr>
            <th colspan="2"  style="border: solid 1px #ccc; padding: 5px; background:#c2dcff; text-align:center; font-weight:bold; color: red;"><?php //echo $nume; ?></th>
            <th style="border: solid 1px #e7e6e6; padding: 5px; width: 1%;">ID</th>
            <th style="border: solid 1px #e7e6e6; padding: 5px; "> NAME </th>
            <th style="border: solid 1px #e7e6e6; padding: 5px; "> AFFILIATION(S) </th>
            <th style="border: solid 1px #e7e6e6; padding: 5px; "> EVENT(S) </th>
        </tr>
   	<!--</thead> -->
	
        <tbody>
            <?php
            $rowNum = 0;
            $_SESSION['ids_current'] = $sql;
            $r = mysql_query($sql) or die(mysql_error());
            while($idRow = mysql_fetch_array($r)){
                $rowNum++;
		$sql = "SELECT * FROM contacts WHERE id=".$idRow['id'];	 
		$result = mysql_query($sql) or die(mysql_error());

		//CONTACT
		while($row = mysql_fetch_array($result)){
                    $contactId = $row['id'];
                    $contact = $row['title']." ".$row['first_name']." ".$row['middle_initial']." ".$row['last_name']." ".$row['pedigree'];
                    if($rowNum % 2 != 0){ ?>
                        <tr style="border-bottom: solid 1px #ccc;">
                        <?php
                    }else{ ?>
                        <tr style="border-bottom: solid 1px #ccc; background: #eef3f7;">
			<?php
                    }

                    echo "<td valign='top' style='border: solid 1px #e7e6e6; width: 1%; padding: 5px; background: #c2dcff'>";

                    if(isset($_SESSION['user']) && isset($_SESSION['login'])){ ?>
                        <!--document.getElementById('profile').className='current';  -->
	       		<img src="images/b_edit.png" onClick="editProfile('<?php echo $contactId; ?>'); setClass('profile'); return false;" onmouseover="this.style.cursor='pointer'" >
                        <?php
                    }else{ ?>
 	       		<img style="opacity: 0.4; filter: alpha(opacity=40);" src="images/b_edit.png">
			<?php
                    }
                    
                    echo "</td>";
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; width: 1%; padding: 5px; background: #c2dcff'>";
                    if(isset($_SESSION['user']) && isset($_SESSION['login'])){ ?>
                        <img src="images/b_drop.png" onClick="deleteRecord('<?php echo $contactId; ?>', '<?php echo $contact; ?>', '<?php echo $start;?>'); setClass('contacts'); return false;" onmouseover="this.style.cursor='pointer'" >
                        <?php
                    }else{ ?>
 	       		<img style="opacity: 0.4; filter: alpha(opacity=40);" src="images/b_drop.png">
			<?php 
                    }

                    echo "</td>";
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; color: #446087; font-weight: bold;'>".$idRow['id'];
		    echo "</td>";
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; width: 20%; color:#446087; font-weight: bold;'>";
                    //forms/profile_form.php?contactId="+contactId
                    if(isset($_SESSION['user']) && isset($_SESSION['login'])){
                        echo "<a href='#' onClick=\"editProfile('$contactId'); setClass('profile'); return false;\">".$contact."</a>";

                    //echo "<a href='#' onClick=\"editProfile('forms/profile_form.php?contactId=$contactId'); setClass('profile'); return false;\">".$contact."</a>";
                    }else
                        echo $contact;
                    echo "</td>";

                    //INSTITUTION
                    $c = 0;
                    $inCellDiv = "insCellDiv".mt_rand();
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; height: 150px; width: 45%;'>";
                    echo "<div id='".$inCellDiv."' style='height: 150px; overflow-x: hidden; overflow-y: hidden;' onMouseOver=this.style.overflowY='auto'; onMouseOut=this.style.overflowY='hidden'>";
                    $institutionIds = $data->getData("institution_id", "contacts_institutions", "contact_id", $contactId);
                    $instNumRows = mysql_num_rows($institutionIds);
                    
                    while($row = mysql_fetch_array($institutionIds)){
                        $c = $c + 1;
                        $institutionId = $row['institution_id'];
                        $institutions = $data->getData("id,institution,address,add_line2,add_line3,category,type", "institutions", "id", $institutionId);
                        echo "<table style='width: 100%; padding-bottom: 0px; margin-bottom: 10px;'>";
                        while($institutionRow = mysql_fetch_array($institutions)){
                            echo "<tr><td width='100px'>Institution:</td>";
                            echo "<td>";
                            echo "<b><i><font color='#446087'>".$c.". ".$institutionRow['institution']."</font></i></b>";
                            echo "</td>";
                            echo "</tr>";
                            echo "<tr>";
                            
                            $add = "";
                            $add .= $institutionRow['address'];
                            
                            if($institutionRow['add_line2'] != ""){
                                if($add != ""){
                                    $add .= ", ".$institutionRow['add_line2'];
                                }else{
                                    $add .= $institutionRow['add_line2'];
                                }
                            }

                            if($institutionRow['add_line3'] != ""){
                                if($add != ""){
                                    $add .= ", ".$institutionRow['add_line3'];
                                }else{
                                    $add .= $institutionRow['add_line3'];
                                }
                            }
                            
                            echo "<td>Address: </td><td><font color='#0000ff'>".$add."</font></td>";
                            echo "</tr>";
                            echo "<tr>";
                            echo "<td>Category: </td><td><font color='#0000ff'>". $institutionRow['category']."</font></td>";
                            echo "</tr>";
                            echo "<tr>";
                            echo "<td>Type: </td><td><font color='#0000ff'>". $institutionRow['type']."</font></td>";
                            echo "</tr>";
                        }

                        echo "<tr>";
                        $d = 0;
                        echo "<td>Designation: </td>";
                        echo "<td style='color: #0000ff;'>";
                        $designationIds = $data->getIds("designation_id", "contacts_institutions_designations", $contactId, $institutionId);
                        
                        while($designationIdRow = mysql_fetch_array($designationIds)){
                            $designationId = $designationIdRow['designation_id'];
                            $designations = $data->getData("id,designation", "designations", "id", $designationId);
                            $numRows = mysql_num_rows($designationIds);
                            ++$d;

                            while($designationRow = mysql_fetch_array($designations)){
                                echo $designationRow['designation'];
                            }
                        }

                        echo "</td>";
                        echo "</tr>";
                        echo "<tr>";
                        $n = 0;

                        echo "<td>Contact #(s): </td>";
                        echo "<td style='color: #0000ff;'>";
                        $numberIds = $data->getIds("number_id", "contacts_institutions_numbers", $contactId, $institutionId);
                        while($numberIdRow = mysql_fetch_array($numberIds)){
                            $numberId = $numberIdRow['number_id'];
                            $numbers = $data->getData("id,number,type", "numbers", "id", $numberId);
                            $numRows = mysql_num_rows($numberIds);
                            $n = $n + 1;

                            while($numberRow = mysql_fetch_array($numbers)){
                                echo $numberRow['number']."(".$numberRow['type'].")";
                                if($n < $numRows)
                                    echo ", ";
                                }
                            }

                            echo "</td>";
                            echo "</tr>";

                            echo "<tr>";
                            echo "<td valign='top'>";
                            echo "Emails: ";
                            echo "</td>";
                            echo "<td>";
                            
                            $em = 0;
                            $emailIds = $data->getIds("email_id", "contacts_institutions_emails", $contactId, $institutionId);
                            while($emailIdRow = mysql_fetch_array($emailIds)){
                                $emailId = $emailIdRow['email_id'];
                                $emails = $data->getData("id,email", "emails", "id", $emailId);
                                $nRows = mysql_num_rows($emailIds);
                                $em++;

                                while($emailRow = mysql_fetch_array($emails)){
                                    $email .= $emailRow['email']. "/". $emailRow['id']. ",";
                                    echo "<font color='#0000ff'>".$em.". <u>".$emailRow['email']."</u></font>";
                                }

                                echo "<br>";
                            }

                            echo "</td>";
                            echo "</tr>";
                            echo "</table>";
			}

                        echo "<div>";
			echo "</td>";
			$evCellDiv = "evCellDiv".mt_rand();
			echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; height: 150px; width: 25%;'>";
			echo "<div id='".$evCellDiv."'style='height: 150px; overflow-x: hidden; overflow-y: hidden;' onMouseOver=this.style.overflowY='auto'; onMouseOut=this.style.overflowY='hidden'>";
			$e = 0;
			$result = $data->getFields("event_id, date_id", "events_dates");
			while($row = mysql_fetch_array($result)){
                            ++$e;
                            $eventId = $row['event_id'];
                            $dateId = $row['date_id'];
                            $where = "id='".$dateId."'";
                            $dates = $data->getFields("date", "dates", $where);
                            $dateRow = mysql_fetch_array($dates);
                            $date = $dateRow['date'];
                            
                            $where = "id='".$eventId."'";
                            $events = $data->getFields("event", "events", $where);
                            $eventRow = mysql_fetch_array($events);
                            $event = $eventRow['event'];
                            
                            echo "<b><i><font color='#446087'>".$e. ". ".$event."</font></i></b>";
                            echo "<br>";
                            
                            $where = "contact_id='".$contactId."'";
                            $where .= " AND (date_id='".$dateId."' AND event_id='".$eventId."')";
                            $sessionIds = $data->getFields("session_id, invited, confirmed, attended", "contacts_events_dates", $where);
                            $sessionStr = "";
                            
							$invited = "NO";
							$confirmed = "NO";
							$attended = "NO";
                            while($sessionIdRow = mysql_fetch_array($sessionIds)){
                                $invited = ($sessionIdRow['invited']) ? "YES" : "NO";
                                $confirmed = ($sessionIdRow['confirmed']) ? "YES" : "NO";
                                $attended = ($sessionIdRow['attended']) ? "YES" : "NO";
                                if($sessionIdRow['attended']){
                                    $sessionId = $sessionIdRow['session_id'];
                                    $where = "id='".$sessionId."'";

                                    $sessions = $data->getFields("session", "sessions", $where);
                                    $sessionRow = mysql_fetch_array($sessions);
                                    $session = $sessionRow['session'];
                                    if($sessionStr == "")
                                        $sessionStr = $session;
                                    else
                                        $sessionStr .= ", ".$session;
                                }
                            }
                            
                            echo "Date: ";
                            echo "<font color='#0000ff'>".$date."</font>";
                            echo "<br>";

                            echo "Session(s): ";
                            echo "<font color='#0000ff'>".$sessionStr."</font>";

                            //echo $session_Id;
                            echo "<br>Invited?: <font color='#0000ff'>".$invited."</font>";
                            echo "<br>Confirmed?: <font color='#0000ff'>".$confirmed."</font>";
                            echo "<br>Registered/Attended?: <font color='#0000ff'>".$attended."</font>";
                            echo "<br><br>";
			}
			echo "<div>";
			echo "</td>";
                    }
                }
                echo "</tr>";
                echo "</tbody>";
                echo "</table>";
}


function viewLimitedContacts($sql, $start, $nume){
    $data = new library; ?>
    <table style='width: 100%; padding: 0px;background: #fff; border: solid 0px #ccc;'>
        <!-- <thead style="background: #eef3f7; color: #666; font-weight: bold; width: 5%; font-size:14px; text-align: center;">-->
	<tr>
            <th style="border: solid 1px #e7e6e6; padding: 5px; width: 1%;">ID</th>
            <th style="border: solid 1px #e7e6e6; padding: 5px; "> NAME </th>
            <th style="border: solid 1px #e7e6e6; padding: 5px; "> AFFILIATION(S) </th>
        </tr>
   	<!--</thead> -->

        <tbody>
            <?php
            $rowNum = 0;
            $_SESSION['ids_current'] = $sql;
            $r = mysql_query($sql) or die(mysql_error());
            while($idRow = mysql_fetch_array($r)){
                $rowNum++;
		$sql = "SELECT * FROM contacts WHERE id=".$idRow['id'];
		$result = mysql_query($sql) or die(mysql_error());

		//CONTACT
		while($row = mysql_fetch_array($result)){
                    $contactId = $row['id'];
                    $contact = $row['title']." ".$row['first_name']." ".$row['middle_initial']." ".$row['last_name']." ".$row['pedigree'];
                    if($rowNum % 2 != 0){ ?>
                        <tr style="border-bottom: solid 1px #ccc;">
                        <?php
                    }else{ ?>
                        <tr style="border-bottom: solid 1px #ccc; background: #eef3f7;">
			<?php
                    }
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; color: #446087; font-weight: bold;'>".$idRow['id'];
		    echo "</td>";
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; width: 20%; color:#446087; font-weight: bold;'>";
                    //forms/profile_form.php?contactId="+contactId
                    if(isset($_SESSION['user']) && isset($_SESSION['login'])){
                        echo "<a href='#' onClick=\"editProfile('$contactId'); setClass('profile'); return false;\">".$contact."</a>";

                    //echo "<a href='#' onClick=\"editProfile('forms/profile_form.php?contactId=$contactId'); setClass('profile'); return false;\">".$contact."</a>";
                    }else
                        echo $contact;
                    echo "</td>";

                    //INSTITUTION
                    $c = 0;
                    $inCellDiv = "insCellDiv".mt_rand();
                    echo "<td valign='top' style='border: solid 1px #e7e6e6; padding: 5px; height: 105px; width: 45%;'>";
                    echo "<div id='".$inCellDiv."' style='height: 105px; overflow-x: hidden; overflow-y: hidden;' onMouseOver=this.style.overflowY='auto'; onMouseOut=this.style.overflowY='hidden'>";
                    $institutionIds = $data->getData("institution_id", "contacts_institutions", "contact_id", $contactId);
                    $instNumRows = mysql_num_rows($institutionIds);

                    while($row = mysql_fetch_array($institutionIds)){
                        $c = $c + 1;
                        $institutionId = $row['institution_id'];
                        $institutions = $data->getData("id,institution,address,add_line2,add_line3,category,type", "institutions", "id", $institutionId);
                        echo "<table style='width: 100%; padding-bottom: 0px; margin-bottom: 10px;'>";
                        while($institutionRow = mysql_fetch_array($institutions)){
                            echo "<tr><td width='100px'>Institution:</td>";
                            echo "<td>";
                            echo "<b><i><font color='#446087'>".$c.". ".$institutionRow['institution']."</font></i></b>";
                            echo "</td>";
                            echo "</tr>";
                            echo "<tr>";

                            $add = "";
                            $add .= $institutionRow['address'];

                            if($institutionRow['add_line2'] != ""){
                                if($add != ""){
                                    $add .= ", ".$institutionRow['add_line2'];
                                }else{
                                    $add .= $institutionRow['add_line2'];
                                }
                            }

                            if($institutionRow['add_line3'] != ""){
                                if($add != ""){
                                    $add .= ", ".$institutionRow['add_line3'];
                                }else{
                                    $add .= $institutionRow['add_line3'];
                                }
                            }

                            echo "<td>Address: </td><td><font color='#0000ff'>".$add."</font></td>";
                            echo "</tr>";
                            echo "<tr>";
                            echo "<td>Category: </td><td><font color='#0000ff'>". $institutionRow['category']."</font></td>";
                            echo "</tr>";
                            echo "<tr>";
                            echo "<td>Type: </td><td><font color='#0000ff'>". $institutionRow['type']."</font></td>";
                            echo "</tr>";
                        }

                        echo "<tr>";
                        $d = 0;
                        echo "<td>Designation: </td>";
                        echo "<td style='color: #0000ff;'>";
                        $designationIds = $data->getIds("designation_id", "contacts_institutions_designations", $contactId, $institutionId);

                        while($designationIdRow = mysql_fetch_array($designationIds)){
                            $designationId = $designationIdRow['designation_id'];
                            $designations = $data->getData("id,designation", "designations", "id", $designationId);
                            $numRows = mysql_num_rows($designationIds);
                            ++$d;

                            while($designationRow = mysql_fetch_array($designations)){
                                echo $designationRow['designation'];
                            }
                        }

                        echo "</td>";
                        echo "</tr>";
                        echo "</table>";
                    }
                    echo "<div>";
                    echo "</td>";
                }
            }

            echo "</tr>";
            echo "</tbody>";
            echo "</table>";
}


Re: Sorting the Data

Posted: Wed Feb 08, 2012 5:33 am
by Celauran
ryojinaiseki wrote:Is there any way that I can sort out just the date only?
I'm not sure what you mean. The first query is sorted only by date.

Re: Sorting the Data

Posted: Thu Feb 09, 2012 1:01 am
by ryojinaiseki
edit: changed the file that I've sent. i'm still a noobie for editing this kind of stuffs.

Re: Sorting the Data

Posted: Thu Feb 09, 2012 5:09 am
by ryojinaiseki
*bump*