Flexible PHP / MySQL pagination - php

On my website I have quite a lot of pages that need to be paginated. I have solution for that, but it requires to put pagination function in each page. I searched for something flexible like having pagination function in one file (say pagination.php) and use it to paginate various data from database, so different mysql_queries and html output. But I was not able to find anything useful.
So could anyone please suggest php pagination function that would be flexible, so paginate data from different queries and outputs that are established on different pages.

There are several examples on the web to get you started, thats where I'd start:
http://www.phpclasses.org/search.html?words=pagination&x=0&y=0&go_search=1
http://www.phpsnaps.com/snaps/view/php-pagination-class/
http://www.phpbuilder.com/board/showthread.php?t=10283679
http://phpsense.com/2007/php-pagination-script/

Very good question. PHP frameworks like Zend or Joomla have their own solutions. If you don't use any PHP framework you will probably need to develop your own solution (your own library). Once I did it using javascript library "datatables", with my own server-side code. Examples on this can be found here in section "Server-side processing".

Related

How do I migrate a PHP based website to Joomla?

I have a PHP based website, with database connections, form processing, etc, that I need to use a CMS on. I'm trying to use Joomla but after using it for 2 days and reading tutorials on it I'm getting the impression that it's designed to handle static content and that all form processing is to be handled by 3rd party extensions.
Am I getting the wrong impression? Is there a standard way to import a PHP website into a Joomla CMS?
I inherited a Joomla 1.5 site a few months ago, so I was in a similar situation to you - where to begin, with lots of questions about Joomla, its ethos, etc. What I've learnt in the meantime is:
Joomla is very heavily dependent on 3rd-party extensions. Some of these are good, some not so good - evaluation and caution is advised.
Joomla encourages the use of extensions, even for relatively static content. Whether these are full blown 'components', or 'modules', depends on quite how powerful/flexible they need to be.
The MVC architecture that underlies everything has its positives and negatives. On the plus side, if everything is done consistently, there is a good separation of concerns and - in particular - the template system offers good configurability. On the downside, very simple components/modules have an awful lot of complexity - e.g. just in terms of number of files.
Joomla is open-source ... sort of. If your familar with the open-source community, you might be a bit disappointed with Joomla, especially when it comes to 3rd-party extensions. Many of them do not embrace the open source ethos, and try to sell code and/or support so, to reiterate, choose your extensions carefully.
Writing your own extension is fairly simple, especially if you're familiar with PHP. Although the documentation isn't great, there are some gems - in particular, take a look at:
http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
http://docs.joomla.org/Accessing_the_database_using_JDatabase
When it comes to forms, I'm still undecided. The site I've inherited uses a third-party extension to manage them (mod_breezingforms), but it has its issues. If you have the luxury of trying out several alternatives, take it.
Run your development site in debug mode. Take a look at database queries. In my own experience, Joomla is very, very demanding on the database. For example, I have some pages that make hundreds of calls to the database with every request. Watch out for this.
At some point, you'll see itemid in the URL and wonder what on earth it is. It refers to a menu item. Menus in Joomla are a bit more general than you might think - they don't necessarily represent a 'menu' and they're quite important. For example, the built-in way to include content on a series of pages is for them to belong to the same menu item, so you might need to create 'fake' menus to house content.
Try MODx Revolution. You can insert your existing php form processors straight into Snippets with next to no modification required, or using the existing FormIt extra. Ajax is easy as pie.
Some docs to get your started:
Overview
Making Sites with MODx
Snippets
edit: apologies if it looks like I've tried to hijack this thread, somehow missed the fact the question is referring specifically to Joomla. MODx is definitely worth a look though ;)
There aren't many CMS's that can handle forms correctly (maybe only the very very generic ones, such as contact me forms, or shopping carts), but for any other purpose, you probably want to use your own PHP script to handle and process the form.
Nothing is stopping you from having a CMS on one part of the page, and your own PHP script on another.
I've once had a website with 2 different CMS's (Wordpress and Joomla), as well as some custom made pages. Slightly trickier to handle, but it's possible.
This question is very broad to answer. There are few step-by-step tutorial available on the internet for this.
From Joomla
Site Ground tutorial
If you follow this head start. You are sure to know a lot of joomla along way and convert your website to the joomla.
BUT, it is easier to build on Joomla rather than convert to it
The first trick to using Joomla effectively is to not over think things and use code that is proven so you don't have to work so hard.
Your existing content can likely be imported to Joomla just be exporting it to a CSV then importing back in to the Joomla article table.
Form handling is incredibly easy. There are dozens of form handling extensions, some of which do more than you will likely ever need. I use ChronoForms most of the time because it can be made to do basically anything once you learn how it works. I also like RSForms if you need non-tech people to be able to create forms on their own.
"Load dynamic data" in to a Joomla article is not very specific, but I'll take a stab at it. If you mean getting user submissions, then there are front end content submission options built in. If you mean loading data from another source, then you can generally use either a module or a plugin to get that data loaded either on the page or actually within the article itself.
Spend a little time getting to know how it works. Learn the difference between a component, plugin, and module and that will help you get a better grasp of what you can do. Joomla is an extensible framework, there's nothing you can't make it do and many things that are already built for you.
I would use JUMI, a Joomla component for embending your own PHP scripts. No scripts modifications are required!

PHP Datagrid class - Supporting sort, print, search, open source

I am a newcomer in the PHP world, and I am building a relatively simple application. Basically, I need to present some data from a MySQL database in a datagrid. I have been looking for a very simple datagrid, which should support, at least, sorting, printing, searching and it must be based in open source.
I have seen a lot of them in Internet, but most of them are commercial, outdated, or they do not support some of the features I aforementioned.
May I know what are your preferences for Datagrids in PHP ??
Thanks in advance
It seems the only actively maintained datagrid for PHP is still the one from phpgrid.com.
tutorials link
Disclaimer: I work for PHP Grid Framework.
I think its little late but you can also check this PHP Grid Framework solution. It's pretty simple to use than others. It has a free version too.
Watch 1 Minute Demo:
I like this one: http://zfdatagrid.com/

What is the best to learn next to aply extra functionality to CMS templates?

I've learned CSS and HTML, what should I learn next if my goal is to create templates for Joomla and WordPress? Ajax? PHP? JS?
I poked around and haven't found a question that is alike so I posted this one
Both Joomla and Wordpress are PHP applications, so in order to understand what exactly happens with your templates and in order to override template parts succesfully, it surely is a good idea to learn some basic PHP.
Now Javascript and AJAX are two different pairs of gloves and the terms belong to two different levels of abstraction.
Javascript is a scripting/programming language while AJAX is a technology which makes use of Javascript. Learning Javascript is definitely a MUST if you're in the UI design area. And once you know it, using AJAX (asynchronous javascript communication with the server) scripts will be one of your possibilities.
So, if I were you (but it also depends on the task at hand) I would learn Javascript (jQuery as a library) first and later look into some basic PHP.
From your question the best answer I can give is:
Install Joomla & Wordpress, then start tinkering with the templates
See how the templates are structures what the different template engines are
Modify the default templates to create some changes you can see.
Add jQuery if you so choose, and try some JS/Ajax tutorials (jQuery has plenty of demos)
View the completed changes in your CMS templates.
Otherwise from your question going to read about something, isn't going to help you 'learn' you need to start with baby steps and work your way into more complex examples. Then just exmplore with either technology and see how others are doing it. Always review and correct, and learn from your mistakes.
A little bit of php will surely help you, but if the developer (or the cms) is good you'll never have to edit the php parts (you should see just many foreach, while, if, else loop/condition)
Js (ajax) is used (sometimes, mis-used) to handle some layouts elements, so yes, take a look at jQuery, but remember: never rely just on javascript.

open source php search and pagination script?

i have a database full of rows of data.
i need an open source php search and pagination script.
so all i need to do is hook it up to the database, and results will be paginated. also the searching function optimized already....
Your question is so "freeform" so my answer is also. Take a look at the Zend Framework Pagintor and Search modules:
http://framework.zend.com/manual/en/zend.paginator.html
http://framework.zend.com/manual/en/zend.search.lucene.html
Paginator is very good and easy to use. Easy to integrate with somesort of caching and etc, but I have never really used search, so I cant comment on that.
Yii framework has exactly what you need. Take a look here:
http://www.yiiframework.com/doc/api/CPagination

Simple web page layout and templating in PHP

In the past I've written sites in ASP.NET just to get nice reusable templating via master pages (layouts) and user controls (partials). I'm talking about sites that have no more complicated code in them than simple variable substitution in templates - I'm just using it to keep my HTML organized. It's great to be able to define the basic layout of your page in one file, and then just fill in the holes for each individual page, re-using some common bits as user controls.
However, I'd rather not continue using Windows hosting, so I'd like to write static pages in PHP, which runs everywhere. In the past I've written myself a poor-man's user control for PHP that just unpacks an array and includes a template, but that's clunky and still requires me to put PHP includes all over my pages. I feel like Smarty or one of the other big templating languages for PHP is overkill for just organizing some "static" pages.
I've considered just doing the pages in Ruby on Rails because I really like HAML/SASS and the layout/partial model, but having a whole rails app for static content seems silly. But I haven't found anything that seems just right in PHP. Can any PHP gurus recommend anything? I want something more sophisticated than "include" but I don't really need much. That said, something that could give me layouts/partials AND HAML/SASS would be heaven. I've looked at phammable but it doesn't look like it solves the layout/partial problem.
Again, I'm not looking for something as complex as Smarty, and I don't want a full CMS. I just want something that will let me properly modularize the HTML of my site. We're talking one step beyond static HTML here.
Zend_View supports layouts, partials and placeholders. Also checkout a new templating language called Dwoo which is similar to Smarty but also takes some ideas from Django templating. And finally, Calypso which is a Django template language clone for PHP
If your looking for something simple I would recommended PHP Template Inheritance. Then you can continue to code in straight php.
I just want something that will let me
properly modularize the HTML of my
site.
Look at http://code.google.com/p/hoduli/
With that simple tool you'll be able to write like this:
<h:define name="header">
some header contents
</h:define>
...
<h:header />
<h:include file="middle_part.php" />
<h:footer>
some ...
</h:footer>
I would suggest to you to look at Drupal and its Block templating model. I think its just what you need.
Stacey is about what I was looking for in terms of a simple PHP templating library for static sites.
On the Ruby side, there's StaticMatic, which doesn't even require Ruby support on the server since it generates the whole static site. Very nice (especially since it uses HAML) but you can't have any dynamic elements at all.
From what i understand, you don't want a full fledged cms and no overkill templating engine like Smarty. Php is a templating system and if you want to properly modularize it, that's up to you.
But i understand, those php tags between your html doesn't look pretty. (Although using shorttags minimizes this...)
You can always use PEAR Templating system, it's available by default on most php installations.
I would also recommend the CodeIgniter MCV framework because it's really lightweight. You choose which libraries get autoloaded.
About six months ago, I started using the Zend Framework. I got used to working with layouts and partials, and never wanted to go back creating sites without it. But for small sites, ZF is just too bulky. It's overkill to use ZF for a site that could be done in HTML.
Check out EuropaPHP. It's a super lightweight, PHP based layout framework. It's brand new as a framework, but so far, I like it a lot! It allows me to use layouts and doesn't require a huge library and strict rules to achieve the same results.
Maybe you should take a look at some content management systems. Drupal is famous in PHP.
Drupal really is a simple and extensible CMS. There is a learning curve, but it's strengths are that is starts small out of the box and can grow with your needs and the community is pretty tight about the quality of the code that's written (though I personally find that some of the modules get a little two function happy).
They have a simple stripped down version of the Zen theme, that lets you create the HTML you want to use. Time spent learning this CMS is time well spent, especially if PHP is already your native language.

Categories