Jump to content

PHP Template page populates page using MySQL 'by link clicked'?


Matt B

Recommended Posts

Hi,

 

Is it possible to build a PHP Template page that selects and publishes a row of data from a MySQL Database when a linked is clicked?

 

I would design: Template.php

Text links (perhaps on homepage of navigation bar): ProductA, ProductB and ProductC

 

If you click link ProductA Template.php would display data for ProductA and likewise for ProductB and ProductC.

 

I would also like search engines for find ProductA, ProductB and ProductC PHP pages. (Not just my single Template.php)

 

Any ideas as to how this could be done without designing individual PHP pages for each product?

 

Kind regards,

 

Matthew.

Link to comment
Share on other sites

well depending how you want it to populate you pass a variable or two through either the URL and catch it via a _GET with php. Click the link and the link would act like a normal link but append

index.php?productID=XXX

 

Where "XXX" is the id, or unique variable in the DB that the DB can find the specific product pull the information for it and then display it on the page. But with that your going to want to do some reading on "Sanitizing" and "mySQL Injection Prevention"

Link to comment
Share on other sites

I have two questions regarding that.

 

1. If I use a template page which asks for the information from the row in the MySQL database how much do I have to 'add to the link'??? Just use a Query and Where Function??? How does this link communicate with my Template page?

 

2. Would my template page be populated for the Search Engines??? I want all pages accessible to Search Engines.

 

I look forward to your reply,

 

Matthew.

Link to comment
Share on other sites

Hi MattyB

 

I have a very similar problem. I am pulling 'categories' from a database e.g. sport, current affairs etc etc.

Each category is then listed individually as a link.

When the user clicks a category link, the user is redirected to a page: blog.php .

blog.php then displays all the threads for that particular category.

Well that's what should happen anyway -  I just can't figure out how to store the category id and then communicate that info to the seperate blog.php file.

 

I thought that storing the data using sessions might be a way forward, but that proved to be a dead end. The session data was stroring category info, but the same category id was being strored irrespective of the category selection being made i.e. the user selects 'current affairs' but the displayed data is 'sport'; the user selects 'politics, but the displayed data is 'sport' etc etc

 

So, I'm a bit stuck too. If I manage to find a solution I will post it back in here: but at least you know you are not alone!

 

:)

 

Link to comment
Share on other sites

1. If I use a template page which asks for the information from the row in the MySQL database how much do I have to 'add to the link'??? Just use a Query and Where Function??? How does this link communicate with my Template page?

 

2. Would my template page be populated for the Search Engines??? I want all pages accessible to Search Engines.

 

1. well lets say your page is currently just index.php in the case of pulling a category you could just append "?cat=CategoryName" without the quotes. CategoryName being the token in your DB that you would query for (or product id, or whatever). In your script you would use $_GET['cat'] to catch the variable if it is set or not (bare in mind this is a big thing you want to sanitize, and double check your DB for its existence before doing anything else mysql_real_escape_string() is going to be your friend in the queries you make using that variable, as it is a variable that can be changed by the user at any time manually through the URL. Now in regards to the defualt page that would be thrown up if nothing is found or its not set, that page you would have a list of all the categories or handfuls of random products or whatever that you could link to on that page to pull up other things specificly.

 

2. Your pages is indexed by the search engines through a number of means, one being the links on a page, as they will crawl those links at the least a couple levels deep, meaning if they land on one page and it has a link to another page within the site (ie another category, product whatever) it will go to that page, and continue crawling and indexing the page for what its worth. Which also falls into various other things they crawl based on such as actual content. things wrapped in h1 tags, and paragraph tags for example like a title of a product followed by its description. Most search engines index the first 2000 or so char's of a page on a per page basis dynamic pages or static so if you have a lot of html try to optimize it and make sure the bulk of the content is near the top of those 2000 lines of code. As search engines don't index based on what you see, but what they read they kinda look at it from a view source perspective and attempt to filter out as much of the HTML as possible from the first 2000 or so characters of the page. So in short yea, search engines will index it, but your going to have to read a bit more on SEO to get good rankings as climbing those ranks arent always as simple as one two three..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.