Posts

Showing posts with the label php

Thoughts on LAMP Development(Linux Apache MySQL PHP)

Image
It's about two years since I started on the whole LAMP thing.  Well the circumstances were like this - I was working on a Linux based product and we wanted to develop a data collection software. Now the problem was we wanted a solution that was quick to develop. So we decided on developing a web application instead of desktop application. So we went forward and used LAMP to develop it and we were satisfied with the speed of development. A desktop application in C-GTK or Java would have taken lots of time and the team didn't have any significant expertise in both of them. Although we were fine with html and we got along with PHP just fine. The main part was easily accessible documentation and the ease of coding. So we developed a solution that was basically a bunch of HTML forms with some PHP thrown in so that we could push the data to a MySQL database as well as call some other programs to perform some tasks using Shell Scripts. It wasn't an elegant solution but it got ...

CSV HELL!!!

Image
Recently I had the pleasure to work with CSV files. And it ended in a CSV hell for me! The functionality I wanted wasn't available anywhere (As often happens when you provide custom solutions to your clients!) The client didn't want to rely completely on the system! (I question the need for the system in such circumstances, but the client wanted the system! Brilliant! Kind of like 'hey, I'll be travelling in Bus but just in case lets have that train available and tracks laid out!) Anyway, I couldn't get them to change their preference and so this hell started. Now the situation is the client uses OpenOffice and/or MS Excel to edit the CSV's. They have excelsheets for the data and they export that to csv. I assumed I could write a parser for CSV and that would be it. But when I got to the task I just couldn't figure out the correct logic. One logic worked for some and failed for some other data and the other worked for some and failed for some other. Aft...

Home Grown : 11. PHP Session Management

You must know about PHP's session management. This demo lets you to see how the authentication is done in conjunction with PHP's session management. Look how we have used AJAX to minimize the number of pages and ease up the process flow. We can add SSL for securely sending password to server. We can declare user's profile and accordingly set UI using his Preferences. This way we can provide a personalized experience to users. I'll round up things with this. There are still a number of things that we can do by combining PHP and JavaScript through AJAX. So there'll be more here, just as soon as I stumble upon them... Download the Project from HERE .

Home Grown : 10. Listing files in a folder on Server

This page will help you list the files in a directory in appropriate way. I've coded a function that will give back appropriate file Size. Also I'm listing them according to their creation date so latest files will be on top. Download the Project from HERE .

Home Grown : 9. Database backup with php

Why would we need a Mysql Backup tool using PHP? Well there may be many reasons, when you don't have access to the Database through cpanel/the hosting provider's phpmyadmin panel (Usually admins have them, so they might not give you the full access to the hosting account). All you're concerned is with data in the database. So you can use this php code to backup the database as a SQL file. This is very handy when you want to manually sync the online database with your local database. In out Tutorial project you have this as Page 7. The code is really simple. We make a connection to the database in question. Then we get table structure and later we fetch the data in tables and add it to querystrings to be added to the sql file. Download the Project from HERE .

Home Grown : 8. DataGridView like View

We have reached easily to the paginated view of the data. Now we are going editability to this form. It's really simple. We use JavaScript to modify the DOM and and when editing is done we save the modified data to the database. We have following files: 1. phpDataGrid.php and 2. saveDataGrid.php I made sure that I have unique id for each element of the row and somehow I got hold of that id in the JavaScript. So I pass the row no to my AJAX function. I have a button which performs two tasks depending what we want it to do. One is in edit mode it replaces the text of required fields with input boxes. And in save mode it saves modified data and replaces the input boxes with the modified data. Really it's simple juggling of data around. I have spans for all editable elements so that I can modify their innerHTML easily. I also use labels to get hold of and set the text very easily. I have used the value of button edit (edit and save respectively) to determine modes. After save ...

Home Grown : 7. AJAX AutoSuggest

There are many JavaScript libraries out there that provide autosuggest/autocomplete functionality. I stumbled upon the prototype Library that provides autosuggest functionality in a quite easy way. We need following: 1. Prototype JavaScript Library: http://prototype.conio.net/ 2. A frontend page: Here you can find page phpAutoSuggest.php to be that frontend. We need the id of the field for which we want autoSuggest. Also we need to create a span and pass its Id to the Prototype Javascript. Also needed is a backend page that will give us the set of values that we want displayed as options. That is hintURL.php. Once again we are using help_topic table in mysql database on our local Mysql server. We search for the URL. After creating all above we simple create a new autocompleter as new Ajax.autocompleter() to which we pass the id of field, id of span and the name of backend page. When we type something in URL field we get a list of matching options. The trick here is in coding th...

Home Grown : 6. Pagination with page jump

Today we're going to add a small snippet of code to our previous paginate example and we're going to get page Jump functionality. Now you may ask why is this important? Simply when you have a large number of records arranged sequentially and the user has some general idea where he wants to go so he can just enter an approximate page number and jump there thus saving him so many scrolls through records of literally no importance to him. How do we implement this? It's really simple as we can see that the pagination PHP code passes the page number as a GET parameter in the URL. So we code a small form for user to enter the page number to and we name the input field as page and set the request method as GET. So when this form is submitted the page value that the user has entered will be available to the PAGINATE script in the form of Page parameter. Now this example just stirs the surface, and there are so many things that we can add here. Like automatically taking current...

Home Grown : 5. Pagination with PHP

This might not be that important topic from a web designer's point of view, but when we design an online system concerning data, the presentation of the data becomes very important. Usually the database contains hundreds of entries. And we would be hard pressed to write appropriate queries to retrieve the exact amount of data and to represent it as such. So here we take a look at a small solution that needs us to define What Data, How Much data per page & How to represent that data and then takes care of everything. First lets create a database that will hold our hundreds of entries. Okay lets use mysql database (on your mysql server) itself. We'll create a page to paginate help_topic table. We'll use ps_pagination.php from PHPSense. We have placed ps_paginate file in scripts. We include it in our PHP Page. After we create a connetion to database and fetch required data using a suitable query. Next we create a PS_Pagination object with the required parameters and rec...

Home Grown : 4. NetBeans IDE for PHP development

I'm using the Netbeans IDE for PHP development for last 3-4 Months. There might be something better but for now Netbeans suffices my needs. Still I encourage you to seek alternatives. Perhaps you might get something better. Now you must question : NetBeans is a Java IDE. So why use it for PHP? Well all I can say is that, because it supports PHP. And whatever support it provides is more than enough for me - at least as of now. So we install NetBeans Full Version which comes with all the goodies and also it has PHP support. It supports syntax highlighting for PHP, HTML, JavaScript and CSS. Intelligent autoSuggest is also provided. AutoSuggest works great with HTML and PHP. It's a bit shaky with JavaScript mostly due to JavaScript's loosely typed nature. But then I'm not much good with JavaScript either - hmmm I was doing a joke, serious. Anyway but what little highliting etc works that should be more than enough. Actually I use Mozilla Firefox's FireBug extension t...

Home Grown : 3. A simple AJAX Example

For AJAX you need two things - Some JavaScript on the frontend to make an Asynchronous Request and Something on the Server side to handle that request. We create a XMLHttpRequest object and send a request to the server. When we receive the response, we use JavaScript to modify the page according to the server response. I hope you've gotten and installed the tutorial project and have it working proper. So here we have a button which calls a JavaScript function to make the xmlhttprequest. On server side we have a simple PHP page that replies with some text. Our JavaScript then modifies the page(Or in this case the text input field). That's all AJAX. How can this small technique help us? Well, if you're good with JavaScript and have some innovative mind you can make magic with AJAX. Have you seen the so called infolinks? These are double underlined words on some websites that open a small pop-up (Usually an advertisement) related to that word. See how beautiful this is. Y...

Home Grown : 2. LAMP - modelling a website

Here we'll take a look at how a website looks from a programmers perspectives. We'll take a look at what constitutes it and what should we use for which purpose. 1. HTML: A website has the HTML pages which constitute the look and feel or in other words The Front-end. Plain text files with embedded tags that dictate the Presentation of Information. 2. CSS: We use Cascaded Style Sheets to enhance the looks. We can design colour themes and appearance of text and various page elements. CSS styling thus is a very important part of our exercises. Every HTML tag has some standard attributes which we can manipulate through CSS for streamlined look. We can also define various styling for different portions of our website. 3. JavaScript: JavaScript is the client-side script. We use JavaScript to perform certain operations at client-side that can ease processing of request on Server. E.g. Form Validation. With introduction of technologies like AJAX JavaScript's use has increased...

Home Grown : 1. AJAX-LAMP Introduction

What is AJAX? What is LAMP? LAMP-> Linux Apache Mysql PHP. The acronym stands for the powerful applications we can build by using these four components. Linux is the OS. Apache is the Web Server. Mysql is the Database. And PHP is the language of choice for Server Programming. Thus these four together make for a powerful combination. AJAX means Asynchronous Javascript And XML. AJAX is not a language but a technology which allows us to make server requests using Javascript without leaving current page and depending on the response we can Modify current page's content with the help of Javascript. One simple example would be user enter something in one part of our page and he wants some operation done on that data without leaving the page. Lets say user has a form where he enters his ID and he wants to check whether he's there in the database or not, before filling a lengthy form. Here AJAX comes handy. Using AJAX we can send a request to server as soon he's entered his...