IPB

Career Guidance | Technical Jobs | Walkin Interview & Job Fairs | Fresher Jobs

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
Need help displaying results of FOREACH in 4 columns
Misha Singh
post Nov 21 2009, 12:09 AM
Post #1


Advanced Member
***

Group: Members
Posts: 8,266
Joined: 23-November 08
Member No.: 6,521



Hi guys,

I need some help.:confused:

I have a .inc file for the queries and a separate php file to echo the results.

Now what I want to do is echo 2 results per line, but I can't find the right solution on the internet. Now I am quite new to this, so it might be just my inability to translate the given solutions to my situation.

What I want is that the following foreach:
"foreach($projectStatusEntries as $projectStatusEntry"
displays a total of 10 statusfields as below:

Header1 Value1 Header2 Value2
Header3 Value3 Header4 Value4
Header5 Value5 Header6 Value6
Header7 Value7 Header8 Value8
Header9 Value9 Header10 Value10



Ofcourse it also fine, if the first 5 results are listed in the left column and the other 5 are listed in the right column.

Can anyone help me to get this fixed??
I've been messing around myself for quite some time now, but can't get it to work.

Thanks in advance (i have attached the 2 relevant files below)

This is the .inc file


Quote:





<?php

require_once("domain.inc");

class ProjectStatusEntry extends Domain {
var $projectId;
var $projectStatusId;
var $statusId;

function ProjectStatusEntry($id=0) {
$this->id = $id;
}

}

class ProjectStatusEntryDAO extends DomainDAO {

public static function getAllProjectStatusEntries($projectId) {
$query = "SELECT * FROM project_status_entries WHERE project_id = ".$projectId;
return ProjectStatusEntryDAO::queryProjectStatusEntries($query);
}

public static function findProjectStatusEntryById($id) {
$query = "SELECT * FROM project_status_entries WHERE id=$id";
$results = mysql_query($query);
$line = mysql_fetch_array($results);
$projectStatusEntry = ProjectStatusEntryDAO::getProjectStatusEntryFromResultSet($line);

mysql_free_result($results);

return $projectStatusEntry;
}

public static function findProjectStatusEntryByProjectStatusId($projectId, $projectStatusId) {
$query = "SELECT * FROM project_status_entries WHERE project_id = $projectId AND project_status_id=.$projectStatusId";
$results = mysql_query($query);
$line = mysql_fetch_array($results);
$projectStatusEntry = ProjectStatusEntryDAO::getProjectStatusEntryFromResultSet($line);

mysql_free_result($results);

return $projectStatusEntry;
}

private static function queryProjectStatusEntries($query) {
$query = $query." ORDER BY id";
$results = mysql_query($query);
$projectStatusEntries = array();
if($results) {
while ($line = mysql_fetch_array($results)) {
$projectStatusEntry = ProjectStatusEntryDAO::getProjectStatusEntryFromResultSet($line);
$projectStatusEntries[$projectStatusEntry->id] = $projectStatusEntry;

}

mysql_free_result($results);
}

return $projectStatusEntries;
}

private static function queryProjectStatusEntry($query) {
$results = mysql_query($query);
$projectStatusEntry = null;
if($line = mysql_fetch_array($results)) {
$projectStatusEntry = ProjectStatusEntryDAO::getProjectStatusEntryFromResultSet($line);
}

mysql_free_result($results);

return $projectStatusEntry;
}

public static function getProjectStatusEntryFromResultSet($line) {
$projectStatusEntry = new ProjectStatusEntry();
$projectStatusEntry->id = $line["id"];
$projectStatusEntry->projectId = $line["project_id"];
$projectStatusEntry->projectStatusId = $line["project_status_id"];
$projectStatusEntry->statusId = $line["status_id"];


return $projectStatusEntry;
}

public static function saveProjectStatusEntry($projectStatusEntry) {
if($projectStatusEntry->id > 0) {
$statement = "UPDATE project_status_entries SET "
." project_id='".$projectStatusEntry->projectId."',"
." project_status_id='".$projectStatusEntry->projectStatusId."',"
." status_id='".$projectStatusEntry->statusId."'"
." WHERE id=".$projectStatusEntry->id;
}

else {
$statement = "INSERT INTO project_status_entries (project_id, project_status_id, status_id)"
." VALUES ("
."'$projectStatusEntry->projectId',"
."'$projectStatusEntry->projectStatusId',"
."'$projectStatusEntry->statusId'"
.")"
;
}

$result = mysql_query($statement);

DomainDAO::checkErrors($statement);
DomainDAO::updateId($projectStatusEntry);

return $projectStatusEntry;
}

}

?>





And this is (part of) the PHP file


Quote:





<?php include_once("../includes/pdfheader.inc"); ?>
<?php include_once("../includes/util.inc"); ?>
<?php include_once("../domain/projects.inc"); ?>
<?php include_once("../domain/benefits.inc"); ?>
<?php include_once("../domain/resources.inc"); ?>
<?php include_once("../domain/projectresources.inc"); ?>
<?php include_once("../domain/projectdependencies.inc"); ?>
<?php include_once("../domain/campaigndependencies.inc"); ?>
<?php include_once("../domain/phases.inc"); ?>
<?php include_once("../domain/campaigns.inc"); ?>
<?php include_once("../domain/projectphases.inc"); ?>
<?php include_once("../domain/deliverables.inc"); ?>
<?php include_once("../domain/projectissues.inc"); ?>
<?php include_once("../domain/projectrisks.inc"); ?>
<?php include_once("../domain/businesspriorities.inc"); ?>
<?php include_once("../domain/budgetfundingtypes.inc"); ?>
<?php include_once("../domain/projectstatusentries.inc"); ?>
<?php include_once("../domain/projectstatuses.inc"); ?>
<?php include_once("../domain/statuses.inc"); ?>
<?
import_request_variables("gp", "p_");

$project = ProjectDAO::findById($p_id);
$benefits = BenefitDAO::getAllBenefits($p_id);
$resources = ResourceDAO::getAllResources();
$phases = PhaseDAO::getAllPhases();
$resourceTypes = ResourceDAO::getAllResourceTypes();
$projectResources = ProjectResourceDAO::getProjectResources($p_id);
$projectDependencies = ProjectDependencyDAO::getProjectDependencies($p_id);
$campaignDependencies = CampaignDependencyDAO::getAllCampaignDependencies($p_id);
$projectphases = ProjectPhaseDAO::getAllProjectPhases($p_id);
$deliverables = DeliverableDAO::getAllDeliverables($p_id);
$projectissues = ProjectIssueDAO::getAllProjectIssues($p_id);
$projectrisks = ProjectRiskDAO::getAllProjectRisks($p_id);
$projectBenefits = BenefitDAO::getProjectBenefits($p_id);
$businesspriorities = BusinessPriorityDAO::getAllBusinessPriorities($p_id);
$campaigns = CampaignDAO::getAllCampaigns();
$budgetFundingTypes = BudgetFundingTypeDAO::getAllBudgetFundingTypes();
$projectstatuses = ProjectStatusDAO::getAllProjectStatuses();
$statuses = StatusDAO::getAllStatuses();
$projectStatusEntries = ProjectStatusEntryDAO::getAllProjectStatusEntries($p_id);
$actualprojectphase = ProjectPhaseDAO::getActualProjectPhase($p_id);

?>
<h2>Project Dashboard</h2>

<table border="1" width="100%">
<tbody>
<? foreach($projectStatusEntries as $projectStatusEntry) { ?>
<tr>
<td>
<?=$projectstatuses[$projectStatusEntry->projectStatusId]->projectStatusName?>
</td>
<td class="status<?=$projectStatusEntry->statusId?>">
<?
if(isset($statuses[$projectStatusEntry->statusId])) {
echo $statuses[$projectStatusEntry->statusId]->statusName;
} else {
echo "status $projectStatusEntry->statusId onbekend";
}
?>
</td>
</tr>
<? } ?>
</tbody>
</table>
<?php include_once("../includes/htmlfooter.inc"); ?>





Go to the top of the page
 
+Quote Post

Fast ReplyReply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 17th March 2010 - 02:51 AM