How to efficiently make many (100+) HTML pages with minor differences - php

I'm trying to make 100+ registration pages for my site with minor differences between each one.
For example:
State, Age, Start Date, Client Goal
Page 1 characteristics: California, Age 18-25, Start Date Dec 1, Goal 1
Page 2 characteristics: New York, Age 25-30, Start Date Dec 15, Goal 3
Page 3 characteristics: New Jersey, Age 18-25, Start Date Jan 1, Goal 2
Goal:
It's important that I have separate pages and not just a form or something selected by the user on a single page. Ultimately I'd like to have many more levels of customization than what I have above and would like to control all the pages without having to go in and edit each individually.
Suggested Method:
I was thinking I could make 1 PHP template and use it on every page to pull a unique code from the href to determine what data it gets from the database to display on the page.
To get my page 1 it would be something like:
window.location.href
returns -> mysite.com/CA-18-12-1-G1
Then use that code to set PHP variables which would customize the entire page just by echoing the html with the variables.
Is there a better/smarter/safer way?
I'm fairly new to this.

Think of it this way: you want to make just one page, and you want to render it with 100+ different customizations.
Figure out the common HTML and CSS for your template page, and figure out what needs to change customization-by-customization. You'll have a set of customization parameters when you finish this design work.
Then, design some kind of data structure to hold your customization parameters. A table in MySql with one column for each parameter and one row for each of your 100 customizations might be a good way to do this.
Then write a php program to retrieve the row with the parameters for the customization you want, fill in your common HTML with the customizations, and send it to the browser for your user to fill in.
If you only need two or three custom pages, my advice would be to program them separately. But with 100 you need a template / parameter approach.

For writing a single page and then using the code of that page in multiple pages you can use PHP.
Lets say you have a page named constant.phpand you want to use the code of the page in a different PHP page named home.php. You have to use this code in the home.php where you want the code to be inserted:
<?php include "constant.php";?>
Now the code ofconstant.php code will get inserted in the home.php in the place where you wrote this code.

Related

Codeigniter doing translations from the database

I have been looking around to see if I can learn how to do translations that come from a database.
My aim is to have an admin do the translations for each label in an admin console and when a user selects a language, the site will reload and it will load the translated options from the db instead of having multiple view files in different languages.
So far what I have is adding an extra segment in my url to accommodate different languages ex. www.testwebsite.com/Application/en-US/content
I plan on reading that segment, storing it into a cookie or session and when a new page loads, it retrieves that option from the cookie or session and always loads the right language.
As for the db structure, so far I have
id | label | language | translation
The main issue now is how do I load this properly? My experience so far has taught me that when I want to load a bunch of items from the database, it will come in an array form and in order to access it, I must add a for loop/ foreach loop.
Is there a way to replace the labels without them being in a loop? Or is there a better way to do what I am trying to achieve?

Passing Variables between PHP pages then performing a MySQL search

fairly new to PHP and webdesign.... I have a website which has a bunch of products for vehicles - all of this is stored in a database.
In order to narrow down what products are available, I want to take the user through 2-3 pages where they firstly select what categorey of product they want, then what make of car they have, then the model, then I want to run a mysql query with that information and return the answerson a page.
I already have the code to request the info from a database and then display it on the page, but The way the current website is setup, they are hard coded mysql queries (meaning the user didnt input any data to get there).
So how can I transfer variable between php pages? Page 1 (contains Categorey) - then pass to Page 2 (contains Make) then page to Page 3 (contains Model) then compile the three variavles collections, and pass them to results.php (a standard results page which Gets variables and then searches).
I know this might seem basic, but I am really stumped as to how to get it coded.
If someone can give me an a newbie explanation about how to achieve this? Thank you
You can pass PHP variables through URLs for example
Your HTML code,
<a href='yourPage.php?yourVariable=someValue'>TEST!</a>
Your PHP code,
if (isset($_GET['yourVariable'])) {
$yourVariable = $_GET['yourVariable'];
// Your code here.
}
Now using this you can create what you want with a little bit of tinkering.
Remember
You need to use $_GET because parameters are being passed using the URL and not a POST request.
Don't forget to clean all input.

Effective pagination of decreasing results

I'm working for a client who asks me to prepare a module for its website (written using Yii) with the following features:
It shows 3 elements from a mysql_result, starting from offset=0.
The user can click on any of them to mark them as "read". That makes the desired item to disappear and to appear what would be the following item. That is, if you are showing items 3 4 5 and you click on 4, that item would disappear and appear the number 6, meaning the result would be 3 5 6.
The elements being shown are partial views and the button that "deletes" the item is a widget within each partial view.
The user can move through the list of items using some << and >> arrows to go back and forth the result.
One of the options the client gave to me was to show a list of pages ( 1 | 2 | 3 | 4... and so), but deleting items means the number of pages will decrease at some time in the future, plus if the amount is pretty big, I would need something more flexible such as only showing the current and other 4 pages at most. Another option is to keep the << and >> arrows.
I've tried to convince the client that pagination and a "live list" is a pretty bad idea, but he rejected the idea to limit the visualization to only the first 3 items (keeping in mind that eventually you will delete them and thus will be able to see the following items).
I'm developing it using Yii, MySQL and jQuery, and I'm not able to use CPagination because of this living list. I'm not asking the code, just some guidelines because I got lost the third time I tried doing it.
Some basics about the system:
I got a controller which loads the first 3 items of this module.
I got some actions in this controller that fetches the next item within a page (which may not be the same of the current object, though. One of my problems resides here), and the full page.
Each item is able to mark itself as "read", which will make the item not appearing the next time you fetch some results.
Every 1 second I check for items that have been marked as read, remove from DOM and append some new items using the action I defined in the second bullet.
Every time the user hits the << or >>, I reload the previous/next page (That would not be a problem apparently. If you're in the last page and there aren't more items to add, you just remain there. However if you empty the page, I don't have any method to detect that and scroll one page back).
As you may see, this headache would be easier without the pagination buttons, but the client obligues me to put them. What would you do guys? Thanks in advance
EDIT: The client decided to get the results in a random flavor. There is no more pagination, so the problem has disappeared. The #thaddeusmt answer may not have helped me really much, but I'll give it as valid, as it might be plenty useful for other people with similar problems than mine. Cheers
It seems to me like the CGridView or CListView should basically do this automatically. They support AJAX updating/paging out-of-the-box.
I assume that you have an AJAX action that like "actionMarkRead()" which you are calling when the user clicks. I assume that this sets some database field somewhere saying that the user has "Read" that item. To make this work with the CListView, just make sure that the CDataProvider has a condition which checks that "read" field (might have to JOIN a table, I don't know what your DB looks like). Then, when the list reloads via AJAX, it will have the correct # of pages to represent the smaller number of pages the CDataProvier query is returning.
I just tested this and it works!
The way I tested it is I set up a CGridView with 'ajaxUpdate'=>true,. Then in my CDataProvider I set 'pagination'=>1 to make it easy to test. Then I used the default AJAX actionDelete in my Controller to delete the items. Every time I deleted an item via that AJAX action link in the CGridView, the grid refreshed via AJAX and page count shrunk by 1. Seems to work like a charm!
Cheers and good luck!

virtualy create pages .php script

hopefully someone here will find the answer to this:
Im looking to have a php code that will generate virtual pages for each city in USA, there are about 32,000 cities so to manually create those pages is nearly impossible, that's why I need a script that will create page virtually for example what I mean take a look here :
http://www.tvbydirect.com/directv-deal/
as you can see in the bottom page there are all the states and then when you click there are all the cities in that state, now notice that the page stays the same (header, contact form, footer) but the content is the same just the city name is changed, also in the meta tags.
what line of code, or script can/will do that ?
PHP acts as a dynamic web framework, there would be need to create static pages, as they can be within the dynamic form.
What you should do is generate a database with the required information and then use PHP To display different data depending on the environment its being called from.
For example, if you had the following web adress:
http://somesite.com/places/usa/washington
yo uwould then use the 2 variables usa and washington and then check the database for the required information.
SELECT information FROM palces WHERE country='usa' AND and city='washington'
And then the information returned from the database would be printed in a custom template.

Refresh Using Ajax/PHP

Further to my question yesterday (here), I am working on a webpage that has a section that shows 'live' order details.
The top half of my webpage has Spry Tabbed Panels. One of the panels contains an include call to a separate php page that I have created (getOpenOrders.php). This contains an SQL query to obtain all open orders and then puts the details into a table.
As a result, the table of open orders is shown in the Spry panel. What steps do I now need to take to have this refresh every 15 seconds?
Do you really want to call the database every 15 seconds for each user? isn't that an overload?
I'm not saying that your database will be overloaded, but, thats how you shouldn't do things!
Edited
you should show an image, or the link to that page in order to gt an appropriate answer, because it all depends in what are you doing in the table.
because I don't know, I will give you an answer on what probably is happening.
Because you said that you're new to the ajax world, let's make things simple, and not to complicate on the you should return a JSON object and use it to re populate your table. :)
So we will start with 2 buttons (Previous and Next) so the user can move the data that is showing (you probably don't want to give him/her 100 lines to see right?)
let's say that you have 2 pages, a showData.php and getTable.php, in the showData.php you will need to load jQuery (wonderful for this) and add a little code, but where the table is to be placed, just add a div tag with an id="myTable" because we will get the data from the getTable.php file.
getTable.php file has to output only the table html code with all the data in, without no html, body, etc... the idea is to add inside the div called myTable all the code generated by getTable.php
Let's imagine that getTable.php gets a page variable in the queryString, that will tell what page you should show (to use LIMIT in your MySQL or PostgreSQL database)
You can use jQuery plugin called datatables witch is one of my choices, check his example and how small code you need to write! just using jQuery and Datatables plugin.
The first description follows the jQuery.Load() to load the getTable.php and add as a child of the div and wold do this for the previous and next buttons, passing a querystring with the page that the user requested. It's to simple and you can see the website for that, if you prefer to use the DataTables plugin, then just follow their examples :)
if you, after all this need help, drop me a line.
<META HTTP-EQUIV=Refresh CONTENT="15; URL=<?php print $PHP_SELF ?>">
This should be in between the head tags.
-or-
header('Refresh: 15');
This should be before the head tag and directly after the html tag.
As said by balexandre, a different method should be used. One that does not require a database hit every 15 seconds for every single user that is connected to the site. But, there is your answer anyways.
Although, balexandre makes a very good point, if you do decide that you need a refresh, you could simply do something like this in your JavaScript:
window.onload = function( )
{
setTimeout( 'window.location.refresh( )', 1500 );
}
(I've not tested the above code, so syntax may need to be tweaked a little, but you get the idea)

Categories