I'm trying to build an events page for my band's website using PHP to list our upcoming gigs (I'm still quite new to server side script) And I keep getting the above error displaying on the page in browser. I'm sure there's something simple I'm missing / doing wrong but I can't seem to figure out what it is (I'm struggling to find relevant info online too)
Here is my code on the html / php page
<?php
$body_id = 'gigs'
?>
<?php include($_SERVER['DOCUMENT_ROOT'].'/fragments/html.html'); ?>
<div class="content-left">
<?php
include($_SERVER['DOCUMENT_ROOT'].'/php/arr_gigs.php');
foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {
echo '<span class="top">
\t';
if ($ticket_link = true){
echo '<a href="$ticket_link" onClick="return false;"> BOOK TICKETS </a>
';
};
echo '</span>
';
echo '<span class="bottom">
\t';
echo '<a href="$event_link" class="gig-tag" onClick="return false;">
\t\t';
echo '<span class="when">$day \/ $month - $location</span>
\t\t';
echo '<span class="where">$description</span>
\t';
echo '</a>
';
echo '</span>
';
};
?>
</div>
And here is php/arr_gigs.php where I hope to put in all the gig details, date, location, links etc.
<?php
$gig = [
[28,12,2013,
'The Firebug - Leicester',
'with more awesome bands',
'www.facebook.com',
'www.seetickets.com'],
[19,04,2014,
'Pi Bar - Leicester',
'(acts tbc)',
'www.facebook.com',
''],
];
?>
As far as I know I'm running the latest version of PHP (5.3 or similar) If there's any help or advice someone could give me I'd be really grateful :) Or if you think there's a better way I could achieve the desired effect
The following line of code is not valid in PHP versions prior to 5.5 (this means you are not using PHP 5.5):
foreach ($gig as list($day, $month, $year, $location, $description, $event_link, $ticket_link)) {
If you wish to get all of those values either use the array syntax to access them:
foreach ($gig as $giginfo) {
echo $giginfo['day'];
Or use a while loop:
while (list($day, $month, $year, $location, $description, $event_link, $ticket_link) = each($gig)) {
Or use extract()
(not recommended):
foreach ($gig as $giginfo) {
extract($giginfo);
As for your array, you are using a syntax that is only available in PHP 5.4. So you will need to use array()
syntax instead:
<?php
$gig = array(
array(28,12,2013,
'The Firebug - Leicester',
'with more awesome bands',
'www.facebook.com',
'www.seetickets.com'
),
array(
19,04,2014,
'Pi Bar - Leicester',
'(acts tbc)',
'www.facebook.com',
''
),
);
?>