/    Sign up×
Community /Pin to ProfileBookmark

Showing multiple images

I’m having some trouble with my webcomic; it’s the last part of the comic that needs help.

I have an area where comics are listed by subject (beer, cars, school, etc.).

What I hope to have is for the comics to show up like this:

PAGE 1
<ul>
<li><img src=”beer1″></li>
<li><img src=”beer2″></li>
<li><img src=”beer3″></li>
<li><img src=”beer4″></li>
<li><img src=”beer5″></li>
</ul>

PAGE 2
<ul>
<li><img src=”beer6″></li>
<li><img src=”beer7″></li>
<li><img src=”beer8″></li>
<li><img src=”beer9″></li>
<li><img src=”beer10″></li>
</ul>

Note: each comic used in these lists is actually NAMED, rather than numbered.

The following is my PHP array:

[code=php]<?php include(“./inserts/head.htm”); ?>
<link type=”text/css” rel=”stylesheet” href=”./setup.css”>
<title>Random Subjects</title>
</head>
<body>
<h1>BEER</h1>
<ul class=”comics”>
<?php
$page = (isset($_GET[‘page’])) ? $_GET[‘page’] : 1 # default is page 1
$comics = file(beer_list.array);
for($ix = $page * 5 – 5; $ix < $page * 5 and array_key_exists($ix, $comics); $ix++)
{
echo “<li><img src='{$comics[$ix]}’ alt=’comic’></li>n”; # add style etc. as desired
}
# previous/next stuff
if($page > 1)
{
echo “<a href=’comics.php?page=” . $page – 1 . “‘>Previous page</a>n”;
}
if(count($comics) >= $page * 5)
{
echo “<a href=’comics.php?page=” . $page + 1 . “‘>Next page</a>n”;
}
?> [/code]

And this is the file mentioned (beer_list.array)

[CODE]
../../comics/y1-sem1/badinfluence.gif
../../comics/y1-sem1/beerfrat.gif
../../comics/y1-sem1/homework.gif
../../comics/y1-sem1/officerpete.gif
../../comics/y1-sem1/pocketsized.gif
../../comics/y1-sem1/project.gif
../../comics/y1-sem1/sober.gif
../../comics/y1-sem1/sucker.gif
../../comics/y1-sem2/drunk.gif
../../comics/y1-sem2/derive.gif
../../comics/y2-sem2/alcoholic.gif
../../comics/y3-sem2/alkydonow.gif
../../comics/y3-sem2/drunkcrit.gif
../../comics/y3-sem2/walk.gif[/CODE]

What I get is the following error message:

[QUOTE]

Parse error: syntax error, unexpected T_VARIABLE in C:apachefriendsxampphtdocs!my_pages!coachrandomcollectionssubjectsbeer.php on line 10

[/QUOTE]

Where am I goofing up? Line 10 reads [i]$comics = file(beer_list.array);[/i]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Bootsman123Jul 31.2005 — This
[code=php]
$page = (isset($_GET['page'])) ? $_GET['page'] : 1 # default is page 1
$comics = file(beer_list.array);
[/code]


Should be:
[code=php]
$page = (isset($_GET['page'])) ? $_GET['page'] : 1; # default is page 1
$comics = file("beer_list.array");
[/code]
Copy linkTweet thisAlerts:
@NogDogJul 31.2005 — [code=php]
$comics = file("beer_list.array");
[/code]
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorAug 01.2005 — Thank you. ?

Secondly, my end links are screwy.

[code=php]<?php include("../../inserts/head.htm");
echo ("<link type="text/css" rel="stylesheet" href="../../setup.css">
<title>Random Subjects</title>
</head>
<body>
<h1>BEER</h1>
<ul class="comic">");
$page = (isset($_GET['page'])) ? $_GET['page'] : 1; # default is page 1
$comics = file("beer_list.array");
for($ix = $page * 5 - 5; $ix < $page * 5 and array_key_exists($ix, $comics); $ix++)
{
echo ("<li><img src='{$comics[$ix]}' alt='comic'></li>"); # add style etc. as desired
}
echo ("</ul>");
# previous/next stuff
echo ("<ul class="comiclink">");
if($page > 1)
{
echo ("<li><a href='comics.php?page=" . $page - 1 . "'>Previous page</a></li>");
}
echo ("<li><a href="../../subjects.php">Previous page</a></li>
<li><a href="../../index.html">Back To Main</a></li>");
if(count($comics) >= $page * 5)
{
echo ("<li><a href='comics.php?page=" . $page + 1 . "'>Next page</a></li>");
}?>
</ul>
</body>
</html>[/code]


What I get is the following:

Subjects (Works fine)

Back To Main (Works fine)

1'>Next page (??? Not even a link)[/QUOTE]


What I want is:

Previous page

Subjects

Back To Main

Next page
[/QUOTE]


What's going wrong?
Copy linkTweet thisAlerts:
@BeachSideAug 01.2005 — your quotes are uneven try this...
[code=php]
echo ('<li><a href="comics.php?page=' . ($page+1) . '">Next page</a></li>');
[/code]
Copy linkTweet thisAlerts:
@Mr_Initial_ManauthorAug 01.2005 — [code=php]<?php include("../../inserts/head.htm");
echo ("<link type="text/css" rel="stylesheet" href="../../setup.css">
<title>Random Subjects</title>
</head>
<body>
<h1>BEER</h1>
<ul class="comic">");
$page = (isset($_GET['page'])) ? $_GET['page'] : 1; # default is page 1
$comics = file("beer_list.array");
for($ix = $page * 5 - 5; $ix < $page * 5 and array_key_exists($ix, $comics); $ix++)
{
echo ("<li><img src='{$comics[$ix]}' alt='comic'></li>"); # add style etc. as desired
}
echo ("</ul>");
# previous/next stuff
echo ("<ul id="comiclink">");
if($page > 1)
{
echo ("<li><a href="beer.php?page=" . $page - 1 . "">Previous page</a></li>");
}
echo ("<li><a href="../../subjects.php">Subjects</a></li>
<li><a href="../../index.php">Back To Main</a></li>");
if(count($comics) >= $page * 5)
{
echo ("<li><a href="beer.php?page=" . $page + 1 . "">Next page</a></li>");
}?>
</ul>
</body>
</html>
[/code]


Thanks, Beechside. But I'm still running into glitches. Both the "Previous" and "Next" links go to this URL: [I]/collections/subjects/beer.php?page=[/I]
Copy linkTweet thisAlerts:
@BeachSideAug 01.2005 — Yeah you have to put the parentheses around the...

... ($page-1) and ($page+1) <-Like that ...

...otherwise it will not parse it properly

And I try to stick with the simpliest quote scheme as I can.
[code=php]
echo ('<li><a href="beer.php?page=' . ($page - 1) . '">Previous page</a></li>');
echo ('<li><a href="beer.php?page=' . ($page + 1) . '">Next page</a></li>');
[/code]
×

Success!

Help @Mr_Initial_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...