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

Haha… :slight_smile: I think it almost works but this gives me an unexpected for error:
for ($x=0; $x<=4; $x++) {

Parse error: syntax error, unexpected ‘for’ (T_FOR) in gamesnew.php on line 18

Thank you for your unbelievable help so far, no worries about being tired… it happens…lol.

On the line before, there is a “-” at the end of the line. Remove it. Sorry, it was very late.
I usually never have this much trouble typing! I didn’t get up till an hour ago. Must have been
exhausted! (Not only a lot of work yesterday, but, had to do plumbing in my shower! Had to take
a wall down and what a mess…

I am sure that is just the issue. Let me know!

OK! Works great. :slight_smile: The only thing, is how can I make it work with .html extension instead? .txt was just for that file I sent you… I had to put the code in a txt file to send it on here, my files are html…idk if it matters but I thought it’d be easier to do them html. IF I change it to HTML nothing shows up, but I did get it to work having the code in a txt file for a couple games.

THANK YOU!!! I’m sure my request is an easy change.

I HATE doing handy work, myself.

Ok wait, should I make my game files .php or .html in the long run? What is better? I got it to work with php extension…just not html…

And last questions for now for you to reply to once you see these, lol… What about having it automatically display things properly spaced out? Cave Story instead of cavestory? Which BTW I figured out how to get rid of games/ in the text for the link. I used basename. Which I learned recently. :smiley:

The other question, is what if there’s two lines of text, not one, and then the image gets bumped up, and it looks misaligned? How do I fix this? I have tried to google these things but I am not sure what to look for.

Okay, you need a bit more learning…

So, one of the biggest things that beginners do not think about is that code has two main parts.
First, the displayed part that the user sees on the site’s page. The second is the code behind it.

Your display has a link that has been created BEHIND the scenes. It points to your .HTML file with
the game’s name on it. So, the user does not see that part. It is viewable if they VIEW-SOURCE of
the page, but, it is kinda hidden for the average user.

Why did I explain this? Well, you can place anything you want in that link. So, you can make it a
.PHP file if you wish. That brings us to what is inside that file. If it is just a simple display of a .SWF
file which is the game, then HTML is just fine. Flash files are not secure if they are all in one’s. I mean
if the entire game is inside a flash file, it can be copied. If the flash file has code inside it to make sure
it is running only from your server, then it is secure as it will not run off a laptop or other server. But,
that is another topic. So, your page that is loaded from this routine can be simple HTML. And, of course
you would want to add a button or link on it to allow going back to the main PHP page which reloads
the games list. (Also, with a link to pass back the current page displayed in the pagination system.)

Now, the question of naming… Since server’s allow spaces in file names, you could simply rename each
of the names to fit how you want them displayed. This is okay, but, could cause other issues later on.
Another way would be to rename them with underscores ( “_” ) for spaces. This is a common way to
handle spaces in names. If you use the underscores, it is simple to replace them for displays. It is just
one string-replace function to place spaces into the name wherever there is an underscore. Another
way would be to name your games just numbers and use an array with details inside it. This might be
a better way as if a user looks at the HTML code while playing a game, they would see something like,
“1.html” or “99.html” and that doesn’t tell me much. Looking at the code that plays the flash, they can
see the “1.swf” or “99.swf” and know that, but, they will not see the name of the game at all. This is
probably a better way to go, but, involves keeping an array list of the actual game info. Now, of course,
this will be done INSIDE your games.php file so users can not see any of it. They only see what is sent
out to the browser. You just display the thumbnails, which will be just “1.jpg”, “99.jpg”, etc. And, they
will never see “Ernie’s great shoot-em-up game” title… This does mean that you need to update your
PHP code every time you add a new game!

Another way would be to use MySQL and save everything inside a database.

Oh, and your other note. The GLOB function will load a list of any type of file extension you wish. You
just change it in there. So, any filetype can be located. You could do it on .swf or .html whatever is
needed. And, lastly, if you do use an array to save the list, you can use fancy text with colors for words
or whatever as you could customize them in the array.

Just a lot of ideas for you to look into…

The array sounds not desirable for viewing my files in my folder, since I wouldn’t know which is which. MySQL sounds nice and I understand some of mysql but i will have to look into that. If we do pagination, would it still be easy to change the way the names display later on once I figure it out or something? Like, I could have pages and all but later implement mysql without having to redo pages? My game is within an iframe by the way. You load my index and the game list is in an iframe, when you click a game, it stays within the iframe, and there’s a home, games, and utilities link on top of the page, not in the iframe.

Any way you wish is okay with pagination. As it is now, you load all of the items using GLOB and so it is
already loaded into an array. The “games” array is a list of the names. So, if you know there is 40 games,
or 100 or whatever, you know the number by using the “count” of the array. So, pagination is just showing
a part of them starting at a certain point. Easy enough.

Using SQL is easier because you can can just add a code at the end of the query. But, there is a lot more
to it than needed for this project. So, we can just get it up and running with the GLOB for now… Let me
know when you decide on the naming conventions for the games…

I think I’d prefer SQL because it sounds most efficient and professional out of the options. I apologize for being a newbie about some things…heh

Oh I misunderstood, lol., OK glob is fine. What do you mean by naming convention options then?

Well, if you want to add in SQL, you have to create your database first.
Then, create a table to hold the games. In that you would have to have the following fields:
Game File Name (the real file name, not the displayed version)
Game Display Name (the one you want posted on the page.)

Now, using just those two fields, you can create the data for the display code which you said was
HTML. This can be created from the database info and just "plopped’ into your iFrame. Or just a DIV.
(iFrames are not used anymore. Mostly because they are not as secure.)

So, get your database set up. Set up your table. Enter a few sample game names and filenames.
Then, let me know and we can continue on from there… (Well, basically dump all we already did…LOL)

Just read your other notes…

Okay, the GLOB method you have now is almost done. Just need to add in the pagination.
This way is not as secure because you are using iFrame’s and files stored somewhere.

Now, SQL is more secure and easy to use. So, either way works for me. It’s up to you…

I would like to do SQL but at first thought you wanted to stay with the other, haha. I’m trying to make my SQL table within phpadmin under the database for my site and it’s bothersome. It’s been a while since I’ve been in here so I’m about to just go search to figure this out.

Am I doing it right? LOL!


Well, using the control panel, you have a button on the left to create a new table.
Just name it “Games”. Then, click on SQL tab and it will allow you to enter each of the TWO fields.
Just use the drop-down and select CHAR and type in 255 in the next position…

Then, click on BROWSE or INSERT and enter your data…

Yep, did all that. I inserted data using what’s in that last image. :slight_smile: OK. SO I added a few games, we are go!

Looks good. Now, do you know how to connect to your database? And select a table?
After that it is just a few lines of code…

Okay, first, is it a local host or an online system?

Local for now and for a while. Little flash game site for around the house.

Like this, right?
Took from w3schools

<?php // Create connection $con=mysqli_connect("example.com","peter","abc123","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } ?>

Okay, here is how you open a database, select a table and pull data from it.
(Just the basics, might need tweaking for your games…)

[php]

<?php // Connect to the database and the "games" table... $DB=mysqli_connect("www.yoursite.com","YourUserID","YourPassword","games"); // Check if the connection worked or failed... if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Connected to table, now run a query to pull all the game names... $results = mysqli_query($DB,"SELECT * FROM Persons"); while($row = mysqli_fetch_array($results)) { echo $row['name'] . "'s filename is: " . $row['file']; echo "
"; } // Close the connection which releases memory in the server... mysqli_close($DB); ?>

[/php]

As you can see it is quite simple. All of the data is stuck into the “$row” array and parses thru it…
We would just have to alter our display routine to use these entries. Several easy ways to do that.
So, get that working first. It will read all your names and display them. Once that is working, post
what you have along with the old version and we can combine them.

LOL, yes, I copied it from W3 schools for you… Changing a few areas to be better for you to read…

Funny you went there! I use that site constantly when helping people… Nice going !

Sponsor our Newsletter | Privacy Policy | Terms of Service