Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

One PHP File as Template 2

Status
Not open for further replies.

joatmofn

Technical User
Jan 12, 2003
72
US
I need to change the way I'm doing things right now and need to know if PHP and MySql are the way to go for my project. I understand this isn't the MySql forum but I figure that many of you who use PHP also use MySql.

I have a couple of websites that feature products. The products are represented by product data, eg. name, dimension, price, etc. Additionally, there are 2 primary images for each product, a thumbnail and a larger image. Also, there may be 1 or more additional images.

A single html page shows thumbnails and by clicking on a thumbnail, the associated product page is displayed.

Each product (information and images) is displayed in on its own html page. When I add a new product, I create a new page an insert the unique information and images about the product. Aside from the unique information, all pages are the same, e.g, same navbar, sidebar, copyright, css, etc.

Here's my question...
Rather than create a new html for each product and update the thumbnail page with the newest product thumbnail with a link to the new product page, can PHP in combination with MySql be used to create only one product page where the product information and image names are pulled from the database and used in the php file to display the appropriate product information.

Thanks a bunch for any info that you may be able to provide on this subject.

 
<facetious>
Here's my answer:
Yes, it can. Anything else I can do for you?
</facetious>


What you are trying to do is commonplace.

The core "trick" is to have your script accept GET-method input so that it knows which product's information to display.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Great! Do you have or know of an example?

It seems this can be done without a database by supplying parameters directly from the php file. True? An example of this (without the database would be a great start for me.)

And perhaps a book that would present an example would be appreciated as well.

I looked online for tutorials but didn't find anything other than very basic "hello world" type examples.


Thanks again.
 
No, I neither have nor know of an example. I'm sure there is lots of code out there, though. If you're looking for a complete solution, check out OSCommerce

But in general, I recommend that you make your scripts modular.

The basic layout of the page will be a table. The cells of the table will be various data: list of products, product details, etc.

If your main script generates the framework of the table and uses include() or require() to call functionality to populate the table cells, you can make development a lot more manageable.


I'm not sure what you mean by "supplying parameters directly from the php file", but as I said before, if your script provides GET-method input to itself and other scripts, you can keep track of where your users are clicking. For example, an anchor might look like:

<a href="somescript.php[blue]?product_id=12345[/blue]">Left-handed smoke shifter</a>



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
oscommerce is not at all what I'm looking for, But your tip on the table and example anchor are. Surely there's a PHP book with one or more chapters devoted to this topic.

Thanks just the same.
 
Most PHP books are devoted to teaching a person the ins and outs of the language.

You're asking a fairly deep design question.

OSCommerce may not be what you're looking for, but all the techniques I've been describing are demonstrated there. Even if you don't use it, it's worth poking around in it.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Digging into the guts of OSCommerce is hardly what I would recommend for an example. That would put you off for life. OSCommerce is a decent little package, especially for the price, but it is a good example of how not to write PHP.

I suggest you look at Smarty. You build your page blank with all the html to your hearts content. You put smarty variables where you want the different products pictures, info, etc. to appear. Then you write a little php code that builds a smarty object, gets the data (however you want but a database is certainly handy) and stuffs the data values into the smarty variables and outputs the page.

Over in phpfreaks.net there are some tutorials on this.
and Kevin Yank has an excellent book you can order from sitepoint called building PHP/Mysql websites or something like that.

Free IT practice exams:
 
Just to restate, PHP (and I'd recommend MySQL), would be the way to go with this. If you use the SQL database, you would really only need to pass around a ProductID without having to track everything else. Also, you would be able to generate your forms / lists dynamically from the information in the database.

I have found the the following book to be a real big help with a lot of this. "PHP and MySQL Web Development" by Welling and Thomson (Published by Sam's Publishing). This contains a few nice little examples along the lines of what you are trying to do, including how to set up and query the database.

Also, take a look at the mysql and php sites to see how the interface works. It's pretty easy.
 
I took one look at oscommerce and thought, not a chance. I don't need whole application to illustrate what I'm after. I appreciate the previous two posts for the solid direction provided.

I've been to both, the php and mysql sites and also went to macromedia (I'm using Dreamweaver) and found some decent information there too.

But really, I just wanted a couple of book titles that covered this topic. Smarty seem intriguing as well. Thanks.
 
I like the CORE PHP book (make sure you get the 5 update). Ut has all the functions in it with examples and some good information on the config settings.
Just to add my two penny worth, if you have the catalogur page tieh a link like
<a href="showit.php?catid=1235">PHP Base Ball Cap</a>,
the script showit.php would receive the catid in the $_GET global array. You just now have to gather the data pertinebt to the catid and format the page. The info may be in a database flat files or anywhere you just have to write the PHP to get it.
Is php/mysql the right direction ??, for commenrcla site I would go for .NET and SQLServer 2000+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top