Simple Questions from a Beginner

Hello to all and thank you in advance for any help!

I have a website that is mainly HTML but my forum in built in php.

There are a number of things from the forum I’d like to integrate throughout the rest of the site.

Simplest question first -

How do I call a php function into an HTML page?

Example: I’d like for guests to see a search box for the forums on the front page so that when they enter there search criteria it will redirect them to the forums with the list of options in place.

Again, thank you for taking the time to help out a beginner!

Well, that is actually several questions in one. First, let’s discuss PHP. HTML files are just text files. They have an extension of HTML so the computer knows to send it to the browser. Once inside a brower the HTML files are interpreted and made pretty with CSS. You already probably know all this.

Now, PHP files are simple, too. They are just text files that contain a combination of HTML and PHP commands, along with any others you may use such as Javascript, etc… The one thing that is different in PHP files from HTML is that they only run SERVER-SIDE. This is a critical part of understanding PHP pages. HTML is executed CLIENT-SIDE inside a browser. PHP is executed SERVER-SIDE inside a server system. If you keep that in mind, you will have half the battle with PHP solved!

To prove my statements, right click on ANY webpage in the world and select VIEW-SOURCE. You will see HTML code (RUNS CLIENT-SIDE) , Javascript code (RUNS CLIENT-SIDE) and CSS code (RUNS CLIENT-SIDE). You will never see any PHP code in any page in the world that way. It all runs SERVER-SIDE.

Now, to explain why I told you all this valuable info… A blog/forum is usually a server program that has PHP in it and handles all of the database access to load/write/alter entries and run searches and all the other nice things it does. This server-side code has access to the database. HTML does not. Javascript can using Jquery/AJAX, etc, but since this is not safe and not secure, very few sites use it. PHP on the other hand never gets into the hands of the user or hacker. It stays on the server making it very secure.

Any HTML page can become a PHP version just by changing it’s extension. Now, once you change the extension, it is the same page. But, now you can add PHP code to is between PHP tags. The code you place inside the tags are executed ONLY SERVER-SIDE. Then, they disappear. So, a search engine type of PHP code would use a type-in from the user and process some data in the database and then echo out a result. You would have to study the PHP code inside the blog/forum and find out where it gets it’s info from and the write some posting code either in HTML using a web form or in PHP and then send the info the the page.

This can get very complicated depending on how the forum grabs it’s info for the search engine. Quite often, they blog and forum coders think ahead and add this function to their pages. So, quite often in the docs for the forum, you can find how to do this.

Now that you understand a bit more about HTML vs. PHP, you can ask questions that might help us steer you in the correct course. First, what kind of forum are you using? What program is it if it is a canned one. And, how are you currently calling that search page. For instance, are you planning to call the page using a link on your HTML page or are you programming an actual POST to send to the page? My guess is a link on an HTML page calling a forum page?

So, hope this confuses you enough to ask some further questions. It’s all about learning here!
Ask away…

Actually this is very helpful and immediately solved part of my thinking on the issue.

I’m going to run a couple of tests on the script I already have and see where I stand.

To answer your question its punBB that I am using and I would like people to be able to query the forum from the front page search box and have it direct them to the forum page automatically with the answers to the query.

I am also looking to integrate the punBB login throughout the whole site for the new features that we are working on (prefer registered users).

Another quick question while its fresh in my mind, is there a way to set up a table or array that users could drag and drop lines to put them in whatever order they want and then have the ability for the user to print that out?

If I’m about to stick my toes in the water I’d rather just dive in head first! ;D

I must say the answer is always Y E S ! ! !

ALL things are possible in code ! ! !

Now, as a fairly newbie, I would say to study study study. All is possible, but, the travel to get there can be a pain in the neck!

I took a quick 30 second look at your forum software. It appears to be a standard system. So, let’s say it uses MySQL as most do. You can set up any kind of page to list items and to allow members to sort these items. They can be listed on a page and at the end of each entry you can have an down-arrow and an up-arrow which the user can press. Once either arrow is pressed, the PHP code would move that item up one or down one until the user had them in the order they want. Then they can print it.

Now a few comments on how this might work. Depending on your various knowledge of programming languages, you could use Javascript to move

tags up and down in order or you could just use a post to PHP to handle the changes. PHP would be easier as JS is CLIENT-SIDE and sometimes is a pain. In using PHP, you would have to use a bit of tricky, but, easy code.

So, you have a list of let’s say 10 items. Each item has the up/down arrows. You can make these arrows buttons with ID’s and the PHP code can know which ones were pressed. So, the list you want to allow the user to reorder can be a “form”. In this form EACH up/down button becomes a form-button. Each form-button has an ID/Name attached to it. So, in your PHP script that creates the page and the form it will create the buttons from the DB info and create a button that is called something like UP3 or DOWN15, each one is created when it is displayed from the DB. If button UP5 is pressed, the PHP code when executed will first check the button name to see if the first two chars are UP if so, it checks the rest of the name and finds that it is #5. Then, in the DB, for that user, it reorders the list to move #5 up ONE position. Then, it totally rebuilds the page and that puts the items into place with the #5 item now in the #4 place.

I realize this is all coming out of my mind. But, it will work. It just takes a bit of laying out the global plan for this list that each of your members can reorder. One big problem is that each member can reorder the list. So, you have to keep the current status of the list somewhere. I suggest the DB. Each member can have one extra field and the “current” version of the list can be stored in that. So, you can add a field to the member’s DB called, like, Current_List and the array of the current list can be stored in it. So, each time the UP/DOWN arrows are pressed, the new array would be re-stored into the DB. Then, when the page is refreshed at the end of the PHP code, it would show the NEW verison of the sorted-by-the-user array that it pulls from the DB.

So, this is just a TON of info of idea’s that may help. Of course, to add-in ANY code into a program that you downloaded and installed such as your forum software, you need to learn everything about their software AND learn how to change it or add on your ideal code to improve it. So, go for it!

Let us know when you have further questions… Hope this helps and doesn’t dig too big a hole for you!

Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service