I want a linked image and then the name of the game afterwards linked

[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]

Ok so this is messy and all but what I want is this…

IMAGE HERE, linked to the $page
LINK TO $PAGE, with name that is the title of the page.

For every set, I want image then text and link… the context is that it’s a flash game website and I have a thumbnail I want to link to the game page, then a link with the name of the game showing. Right now it shows the filename, I want it to show name of game AUTOMATICALLY…right now, it also just does all pictures, then all file names linked… Help?

I am the original poster. How do I make new pages automatically as well, like after a certain amount is on first page, the rest go to new pages without making separate page files myself?

Ha! You confused me. I thought we settled this one on the other post…

Anyway, using the new layout that you are creating in the other post, you can just add a counter
to the number of pages that you have displayed.

So, in our example on the other post, you used 5x5. So, if you had, let’s say 1000 items, you would
have to create what is called a “pagination” system. This is usually done by division and planning.

Let’s say 1000 items, 5x5 listed at a time would be 25 at a time. So, you would have to calculate the
number of pages. In our discussion, it would be 1000 / 25. Or a total of 40 pages. You would need
two buttons. One for previous page, one for next page. Previous/next pages would be the next 25
or previous 25. You must check to make sure that a user does not go below the first 25 or above the
top or final page of 25. A little tricky but not too hard. Just have to think out how you handle it all…

One further note. If you are pulling these from a directory, you can grab them all at once. If you are
using this in a database, you can query it as needed and limit it to 25 items, much easier than from a
directory…

Hope that idea helps for you…

This is an older post…lol :slight_smile:

Sorry to confuse you… So can you break it down for me, how I’d do the easier method and get pages working, and the other things I asked about, preferably on the new post? LOL. I know I’m asking a lot…I made the new post because this got no replies.

Well, if you use the “GLOB” command, I will assume that you have a folder full of files.
Correct? If so, then just do it this way.

If you are creating the files from some other code, then, explain and you can make it into
a database app.

So, guess this all depends on where the data is coming from. You have shown images
and site names, So, are all these already in a database? I can help you with the code if I know
what is going on…

Pagination is on just about every big site everywhere. It consists of getting the info somehow and
showing only part of it at a time and allowing the user to “page” thru the data. All standard stuff these
days. Depends on where you get your lists from…

So, let us know…

My files are just in a game folder. :slight_smile: an HTML that has just the swf of the game, the swf, and a jpg for an icon.

Its like xampp/htdocs/mysite/games/game1.swf or HTML or jpg for example…

Okay, then GLOB it is ! Simple enough. Basically we already discussed this already.

Two things. Are you planning the 5x5 as we talked? About how many are you talking about?

And, one issue with using GLOB’s… You are loading them in the order they are in the folders.
Therefore, if you have two games, one named 'ErnieHunt" and one named “ErnieShooter”,
you do NOT know which order the are in. The “Glob” function pulls them in the order they are
stored in the directory not in any special order. Therefore, you will need to sort them. Also, if
the HTML and the JPG are the same name, you only need to load the list once.

So, are the JPG’s and the HTML’s the same names? If so, why not just put the picture inside the
HTML file. Since you have to store the link in that HTML file anyways, also put a link to the picture.
Then, just load one group of HTML files and the pictures are loaded automatically along with the
name. Hmmm, did that make sense?

Pick one game and it’s URL and post it. If you do not want anyone clicking on the game’s URL,
just xxx out some of it. I need to know what you mean by HTML files. If they are really HTML
files, what are in them? I assume the URL of the address of the game? If so, how does it
look inside the HTML file? Could it just be loaded using INCLUDE’s? More info please…

JPG, SWF, and HTML files all have the same name for each game. The JPG is meant to be a thumbnail… HTML file just has an embed for the flash inside it. Internet is awful for communicating, lol. I want the JPG for the correct game to show and be LINKED to the html file that has the same game…then when you click the image, it loads the html file, you see the flash game. BELOW that jpg, I want a link to the html file with the name of the game PROPERLY typed out… right now, it does “game1.html”… I want Game 1 to show, while still being able to just pull things from a directory. I tried renaming my files “Game 1.html” but the internet told me using spaces in file names is improper, and if I did that, I’d want to do it for my images and swfs as well so everything is the same, and that would look bad…

I want each page to have 25 games, 5x5, and right now I only have maybe 1 page worth, but every day, I am adding more games to my directory. Thus the want for automatic new pages to be created. You know, like sites that have like pageid?=2 or whatever it will say? :slight_smile:

I am local ATM but I have provided an HTML file in txt form that is an example. :slight_smile: I do not want the image within the html file, but instead to serve as a thumbnail to view what the game is, sort of, before you go onto the page…and of course to act as a link above the text link, because usually thumbnails for things like that are clickable. I again, am sorry, if my replies are mixed up. I just have trouble organizing things. For me, code helps the most. I don’t know all the aspects of these languages yet so if I can see code and mess with it as I need, that helps me the most.


cavestory.txt (498 Bytes)

All understood now. Easy enough. First, your folder holds everything. So, you only need to load oone of them to create your list. And, we will trim off the extensions and replace them as needed. That is easy with a minor change in your current code. Then, we can create a display that fits your needs. So, first step, alter your code to get just the name of each game.

This should work:
[php]

<?php // Start the table echo ""; // Get names of games from directory $dirname = "games/"; $games = glob($dirname."*.jpg"); // Now display 25 games with links for ($x=0; $x<=4; $x++) { echo ""; for ($y=0; $y<=4; $x++) { // Place each game inside a table's cell (Later on use CSS to make them fit nicely) echo ""; } ?>

[/php]
One note: I altered your code so that the user can click on picture or text. They do not have to just click on the text. Makes it much easier that way. (And, of course added in the table code we talked about in the other thread.)

This is just one page of the display. Next time, we can get the pagination working. But, one step at a time…

Okay, some minor changes. No foreach used. Set number of cells inside the table. Always starts at first game and does 25 if they are there. Checks to see if not there, so if 20 games, it will show all 20 and 5 blanks. (You could alter this to a pix that says “Coming Soon…” which would be nice!) And, no error checking, so if you have a game misspelled, like ernie.jpg and ermie.html it will mess up the display…

I think that will get you started… I’m heading to bed in a bit. But, that is good for now… Pagination will be up next. That is a bit more tricky…

" // Check if there is a file. If not, leave an empty cell, if there is one, display it if (isset($games(x+y*5)) { // First get the name without the extension $temp = substr(trim($game(x+y*5)), 0, -4); // Set up HREF to point to HTML code for the entire table cell (any click inside will go there) echo ""; // Display the picture (inside the anchor to the html file) echo "
"; // Show the name of the game echo "" . $temp . ""; } // End the cell no matter if empty or not echo "

Oh forgot to mention, the cavestory text looks like standard code, so linking to it should be no issue.

Anyway you link to it should work nicely…

Wow! AMAZING. Thank you. I don’t actually have it working, I get this error
Parse error: syntax error, unexpected ‘if’ (T_IF), expecting ‘,’ or ‘;’ in C:\xampp\htdocs\kappachat\games1.php on line 43

but it looks like it will work! And that’s exciting.

Have a great night, I’m excited for pagination.

Haha… fixed that error…needed a ; after an echo… now I get this :

Fatal error: Cannot use isset() on the result of a function call (you can use “null !== func()” instead) in C:\xampp\htdocs\kappachat\games1.php on line 42

with this code

[php] <?php
// Start the table
echo “

”;
 //  Get names of games from directory
 $dirname = "games/";
 $games = glob($dirname."*.jpg");
 
//  Now display 25 games with links
for ($x=0; $x<=4; $x++) {
   echo "<tr>";
   for ($y=0; $y<=4; $x++) {
      //  Place each game inside a table's cell (Later on use CSS to make them fit nicely)
      echo "<td>";

      //  Check if there is a file.  If not, leave an empty cell, if there is one, display it
      if (isset($games(x+y*5)))
      {

         //  First get the name without the extension
         $temp = substr(trim($game(x+y*5)), 0, -4);

         // Set up HREF to point to HTML code for the entire table cell (any click inside will go there)
         echo "<a href='" . $temp . ".html'>";

         //  Display the picture (inside the anchor to the html file) 
         echo "<img src='" . $temp . ".jpg' width='93px' height='74px' /><br />";

         //  Show the name of the game
         echo "<center><b>" . $temp . "</b></center>";
      }

      // End the cell no matter if empty or not
      echo "</td>"; } }

?>[/php]

Oh, sorry, get’n too tired to think… Change it to
if ( trim($games(x+y*5)!="" )

Since the array has at least on item in it, you can test to see if it is set, but have to compare it’s value…
I think that should work.

Didn’t have time to test it as I do not have your folder full of games set up… I will tomorrow if needed…

Replaced and added an extra parenthesis as needed, and get this:

Fatal error: Function name must be a string in C:\xampp\htdocs\kappachat\gamesnew.php on line 26

Now, hopefully you are getting yourself some sleep but so you can see this tomorrow… :stuck_out_tongue:

I would send you my whole website if you need, or just games folder, if you could provide me with a more secure way to send, maybe email or something.

Heading to bed now. Just post the new code that I sent you with your fixes.
I will look at it when I get up in about 8 hours… LOL…

I really think you are almost there… I can make up a folder locally with some game names for testing, just didn’t have time as I am working on a huge project, too… Tomorrow…

[php]<?php
// Start the table
echo “

”;
 //  Get names of games from directory
 $dirname = "games/";
 $games = glob($dirname."*.jpg");
 
//  Now display 25 games with links
for ($x=0; $x<=4; $x++) {
   echo "<tr>";
   for ($y=0; $y<=4; $x++) {
      //  Place each game inside a table's cell (Later on use CSS to make them fit nicely)
      echo "<td>";

      //  Check if there is a file.  If not, leave an empty cell, if there is one, display it
      if (trim($games(x+y*5)!="")){

         //  First get the name without the extension
         $temp = substr(trim($game(x+y*5)), 0, -4);

         // Set up HREF to point to HTML code for the entire table cell (any click inside will go there)
         echo "<a href='" . $temp . ".html'>";

         //  Display the picture (inside the anchor to the html file) 
         echo "<img src='" . $temp . ".jpg' width='93px' height='74px' /><br />";

         //  Show the name of the game
         echo "<center><b>" . $temp . "</b></center>";
      }

      // End the cell no matter if empty or not
      echo "</td>"; } }

?>[/php]

Sleep well!

Tired last night! Also, lots of work this morning and to top it off my computer overheated and I just got it back up… YIKES!

Anyways, ME-BAD! This line #17: if (trim($games(x+y*5)!="")){
Is wrong.

Should be: if (trim($games(x+y*5))!="") {

Wrong paren… Let me know if it works!

No syntax errors but function still needs to be a string it says.

Oh no, that and BSOD’s are the worst!

Well, I was so very tired, I had thrown in a lot of mistypes. Sorry for that.
I was gone all day and just got back. Bed soon again… Anyways, I got it working for you.

Here is the latest version that works for me. I did not finish up the link part, but, let’s get it
to display your items first. Then, the links and then the pagination… So, this code should grab
your list, break it down to the game name, assuming the JPG and HTML have the same names.
I used BORDERS just for now to see how it looks for testing and I put in some text if the table’s
cell is empty. Works on my local host testing server. So, let me know if this works for you!
[php]

<?php // Start the table echo ""; // Get names of games from directory $dirname = "games/"; $games = glob($dirname."*.txt");- // Now display 25 games with links for ($x=0; $x<=4; $x++) { echo ""; for ($y=0; $y<=4; $y++) { // Place each game inside a table's cell (Later on use CSS to make them fit nicely) echo ""; } echo ""; } echo "
"; // Check if there is a file. If not, leave an empty cell, if there is one, display it if (isset($games[$y+$x*5])){ // First get the name without the extension $temp = substr(trim($games[$y+$x*5]), 0, -4); // Set up HREF to point to HTML code for the entire table cell (any click inside will go there) echo ""; // Display the picture (inside the anchor to the html file) echo "
"; // Show the name of the game echo "" . $temp . ""; // And, end the link! echo "
"; } else { // Display whatever for a blank cell echo "New Game Coming Soon!"; } // End the cell no matter if empty or not echo "
"; ?>

[/php]
I added in some comments so it will make sense to you! And, I added in a little formatting so it might
help when you get to the finished product. I must say I am very sorry for being so tired last night and not being able to think straight. As you will see in the above code, I messed up brackets and parens! Most of
the problem was that. That is why the “isset” for the array did not work correctly. Well, anyway, let me
if this works somewhat for you and we can continue with the link testing and pagination…

Sponsor our Newsletter | Privacy Policy | Terms of Service