I have a problem with my code. I have code like this:
<?php
include('php/SelectHistory.php');
include('php/SelectSmallHistoryUser.php');
include('php/SelectSmallHistoryProject.php');
include('php/SelectSmallHistoryFunctionality.php');
$newHistoryRow = SelectHistory();
echo "<table width='100%'>";
if (count($newHistoryRow) > 0)
{
foreach ($newHistoryRow as $current)
{
$chosenUser = SelectSmallHistoryUser($current->userID);
$chosenProject = SelectSmallHistoryProject($current->projectID);
$chosenFunctionality = SelectSmallHistoryFunctionality($current->functionalityID);
echo "<tr>";
echo "<td>" . $chosenUser->fullName . " was busy with " . $chosenFunctionality->functionalityName . " on " . $chosenProject->projectName . " at " . $current->lastModifiedDate;
echo "</tr>";
unset($chosenUser);
unset($chosenProject);
unset($chosenFunctionality);
}
}
else
{
echo "<tr><td>No History To Display.</td></tr>";
}
echo "</table>";
?>
The problem that I have with it is that within the loop, it declares a method which resides in a class. Now because it is working with data from a database, if the amount of things is more than one, I get a “Class already declared” error.
Is there a way I can fix this or is there another method I can use?
This is the right way of creating class :
And the right way of creating an instance of class is :
Mind the
__construct()function and thenewkeyword and try executing your script again.