$currentLanguage = Language::get();
$programLoader = new ProgramLoaderFood();
$allPrograms = $programLoader->getAllFoodPrograms();
$allCousines = $programLoader->getCousineListOfProgram();
$allLocations = $programLoader->getAllRestaurantLocations();
$allTextFood = $programLoader->getAllTextFood();
$jsonAllPrograms = json_encode($allPrograms);
$jsonAllCousines = json_encode($allCousines);
$jsonAllLocations = json_encode($allLocations);
$jsonAllTextFood = json_encode($allTextFood);
I have this piece of code at the start of my page. I need to load in data through a php function (which gets data from our mysql database. I load in the data put it in a class and add it to an array.)
when my page is loaded (mvc pattern) i try to dynamically load in some info about tickets of our event by using javascript (DOM). I try to echo the json_encode into a js variable :
<script>
var allProgramsInfo = <?php echo $jsonAllPrograms ?>;
var allCousinesInfo = <?php echo $jsonAllCousines ?>;
var allLocationInfo = <?php echo $jsonAllLocations ?>;
var allFoodTextInfo = <?php echo $jsonAllTextFood ?>;
var currentLanguage = "English";
insertAllPrograms(allProgramsInfo,allCousinesInfo,allLocationInfo,currentLanguage);
</script>
All of them work except the "var allFoodTextInfo" doesn't work. I get this error : Uncaught SyntaxError: Unexpected token ';' I tried different ways of working around this but I just can't find the solution.
the function that loads in the text info :
public function getAllTextFood() {
//string $query, string $datatypes, array $parameters
$parameters = array(4);
$result = $this->ExecuteSelectQuery("SELECT * FROM www_text WHERE eventID = ?", "i",$parameters);
$allText = [];
while ($textInfo = $result->fetch_object()) {
$loadedText = new CousineTextInfoFormat();
$loadedText->textId = $textInfo->textID;
$loadedText->textTitel = $textInfo->textTitel;
$loadedText->textContent = $textInfo->textContent;
$loadedText->textLanguage = $textInfo->textLanguage;
$allText[] = $loadedText;
}
return $allText;
}
I just don't understand why it works for all the other variables and for the last one it doesn't...
**edit for example this parsing the result of this function does work :
public function getAllFoodPrograms(){
//string $query, string $datatypes, array $parameters
$parameters = array(4);
$result = $this->ExecuteSelectQuery("SELECT * FROM evt_programme WHERE eventID = ?", "i",$parameters);
$allPrograms = [];
while ($programInfo = $result->fetch_object()) {
$loadedProgram = new ProgramFoodFormat();
$loadedProgram->programID = $programInfo->programmeID;
$loadedProgram->eventID = $programInfo->eventID;
$loadedProgram->programDate = $programInfo->programmeStart;
$loadedProgram->programName = $programInfo->programmeHallVenue;
$loadedProgram->programPrice = $programInfo->programmePrice;
$loadedProgram->programTickets = $programInfo->programmeTicketSupplySeats;
$allPrograms[] = $loadedProgram;
}
return $allPrograms;
}