-
Create Divs And Elements at Runtime
Is it possible to have a more or less blank website. And have a script which accesses a MYSQL database using PHP and create elements as required based on values returned, for example like a highscore table.
So when the website is loaded it access the database to see how many scores there are and create that many rows in a table. then add values from the database.
Any existing scripts like this?
-
-
Maybe. It depends on exactly what you're imagining.
Two important concepts:
1. Server-side language: a programming language like PHP (or ASP, CGI, etc) that operates on the server. It can store information (as files or in a database), access that information, and also generate dynamic pages (like the forum we're using now).
2. Client-side language: a programming language like Javascript that can operate in the browser and interact with the user (including responding to input and making active or animated changes on the page).
The two are different things and cannot just magically interact.
The simple way to do what you're describing is to make a dynamic page using a serverside language like PHP. You will create a PHP page that generates HTML that shows whatever you want, based on a database-- and it can be variable in many ways (number of items, content text, whatever).
But if you actually want this to load as a blank page then change and update these things, you'll need to use Javascript. But Javascript (as a clientside language) cannot access the database (among other things).
So you're stuck between two different languages. The simple answer again is to skip the Javascript part. But if you really need that, there's a way to get some information from the server (using Javascript) without reloading the page. That's called Ajax, and it's a method of using Javascript to request the contents of a page on the server-- and that page can be a PHP script so that you can very indirectly get information from the database using Javascript.
So now that we've got the basics out there, do you have a more specific question? If not, then you should just start on some basic tutorials for the languages you'll use, and there are many out there. Wait to look into Ajax until the end because it is very confusing for a beginner (sometimes for an experienced coder too).
The serverside language you use (and one will definitely be needed for this project, while JS and Ajax are optional) will probably depend on your server-- many/most servers have PHP, but there are other options and if you don't have PHP you may have ASP, etc. Or if you don't, you'll need to get a new server (a shared account is fine, as long as you have access to PHP, etc). Only the least expensive (often free) hosts don't have something like this-- for $5/mo you can get PHP and a database, easily.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
can you reccommend a simple tutorial for PHP to do what you suggested?
-
-
Assume you don't need Ajax (animated elements appearing on the page), then this is all fairly standard PHP functionality.
What part is difficult, or do you just not know where to start?
I recommend an introductory tutorial to PHP and MySQL, such as the one here:
http://php-mysql-tutorial.com
(I really dislike the layout of the site, but the information is good-- start at the last entry and work backwards-- oldest to newest.)
Basically you'll just need to use loops to go through the data from the database and display it each time.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks