Relatively URGENT - Having image then text link using glob

[php]<?php

$dirname = “games/”;
$images = glob($dirname.".jpg");
$pages = glob($dirname."
.html");
foreach($images as $image) {
echo ‘
’;
}

foreach ($pages as $page)
{
echo “”.basename($page)."
";
}
?>[/php]

I’m new and I know this is messy and all but what I want is this…

$image, linked to $page


a link to $page with TEXT that is the name of the page, not the filename. Like “Monster Den Chronicles”, a game I have in my db, instead of monsterdenchronicles.html.

The context is that it’s a flash game website. I plan to do a 5 x 5 grid of picture+link below per page.
So for every image, I want the text link using the $page right below it. I know I might need CSS and some more php to do all this, but am not sure how. As stated, right now $page shows the filename, I want it to show name of game AUTOMATICALLY like foreach works… It also just does all pictures in a row, and when finished with pictures in directory, all file names linked… For the life of me I can’t get it to alternate. Help?

I ALSO want to know, on top of those things, how to have it automatically make new pages of the 5x5 grid of games… like page2, page3, etc… without making files myself for new pages.

It’s usually a problem explaining something that is in your mind. Each programmer handles this differently and it is quite hard to understand every programmer’s image of his wishes…

So, now that I noticed nearly fifty reads and no replies… I think it is a question of “What do you want?”

If you want a grid that is 5x5, just place the data into tables. Easiest way out of that.
Since you have the same number of items inside both $images and $pages, you can parse
thru them using a counter. So, instead of parse thru one array of images and then another array
of pages, just use the indexes into the “glob’s”…

Something roughly like:

echo


for x=0 to 4
echo
for y = 0 to 4
echo “”
}
echo
}
echo
” . $images[x+y5] . “
” . $pages[x+y
5] . “

that is untested and just a basic layout of how to handle it.
Something like that should work well for you. try it and post your code if it fails… Good luck…

I am very new to coding so had trouble understanding everything but I put in syntax I THOUGHT I needed…

got this error: Parse error: syntax error, unexpected ‘x’ (T_STRING), expecting ‘(’ in \games1.php on line 28

[php]<?php
echo “

”;
for x=0 to 4
echo “”;
for y = 0 to 4
echo “”;
}
echo “”;
}
echo “
” . $images[x+y5] . “
” . $pages[x+y
5] . “
”;
?>[/php]

THen if I do this, it should be like…
IMAGE IMAGE IMAGE IMAGE IMAGE
NAME NAME NAME NAME NAME

IMAGE IMAGE IMAGE IMAGE IMAGE
NAME NAME NAME NAME NAME

IMAGE IMAGE IMAGE IMAGE IMAGE
NAME NAME NAME NAME NAME

IMAGE IMAGE IMAGE IMAGE IMAGE
NAME NAME NAME NAME NAME

IMAGE IMAGE IMAGE IMAGE IMAGE
NAME NAME NAME NAME NAME

IMAGE IMAGE IMAGE IMAGE IMAGE
NAME NAME NAME NAME NAME
right? and both will be linked to the page accordingly, and then how do I make the page change to the name of the page, not name of the file, automatically? Then what about incorporating pages?

Thanks for your help, I’m just not sure how to connect it to the rest of what I want. :slight_smile:

Well, I didn’t give you actual code. LOL I was giving you a start on how you do it.

A “for” command is done like this:

for ($x=0; $x<=4; $x++) {

I guess I should have thought about you being a newbie… Sorry…

So, replace the two for’s and let us know…

Notice: Use of undefined constant x - assumed ‘x’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant x - assumed ‘x’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant x - assumed ‘x’ in C:\xampp\htdocs\kappachat\games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

Notice: Use of undefined constant y - assumed ‘y’ in games1.php on line 32

games/beventlaed.jpg
games/beventlaed.html games/beventlaed.jpg
games/beventlaed.html games/beventlaed.jpg
games/beventlaed.html games/beventlaed.jpg
games/beventlaed.html games/beventlaed.jpg
games/beventlaed.html

The jpg and html are aligned on top and bottom of eachother like I want, a 5 x 1 setup so far… but it’s doing the same image and game 5 times over. Also they are just the file names. I know how to make it echo an image and all but not with what you added. :stuck_out_tongue: Sorry, I do understand things like chat applications and accounts a bit but stuff like this has me puzzled. LOL. THANK YOU, again.

[php]

<?php

$dirname = “games/”;
$images = glob($dirname.".jpg");
$pages = glob($dirname."
.html");
foreach($images as $image) {
//echo ‘
’;
}

foreach ($pages as $page)
{
echo “”.basename($page)."
";
}
?>

<?php echo ""; for ($x=0; $x<=4; $x++) { echo ""; for ($x=0; $x<=4; $x++) { echo ""; } echo ""; } echo "
" . $images[x+y*5] . "
" . $pages[x+y*5] . "
"; ?> [/php]

BTW I kept my old, working code for NOT what I want above it… I thought it wouldn’t interfere… I made the image echo a comment to kind of cross it out easily for now so they wouldn’t show.

Sponsor our Newsletter | Privacy Policy | Terms of Service