PHP Query Generator/Reporter - php

I'm in the process of tweaking a web application and so far I've had some really helpful guys from here, explaining things in layman's terms. Thank you.
One of the abilities I wanted in my app was the ability to search through records and use the result to generate different kinds of useful reports. In my workplace we use a system like the image below to do just this.
Report Generator
Aside from searching and generating reports, I will need the ability to save a user's search criteria for easy retrieval of future searches.
Is there an easy way to do this?

The image you linked looks a lot like something I have wished for many times. I have thought about diving in and writing my own app but never had a good enough reason to.
I did a bit of searching and discovered that there isn't a lot out there.
This one http://mysql-reports.com/ is pretty basic but would work for someone generating custom SQL statements or for someone that isn't capable of writing their own SQL queries.
I wish I had more ideas! Hopefully someone else will.

Not sure if this is what you are looking for but it might be a start.
PM Report
I've used it with some modification in the past and it has worked well for me. It may not be the prettiest thing in the world but it's a start.

Related

Designing/Visualizing a Mysql database to avoid rework

I have been coding php enterprise applications from many years but still i would like to take a feedback.
Usually when i get the functional specifications, i create a worksheet of how long it will take to finish the project. I don't have a team and i code start to end.
Almost in most of the big applications after reaching the midway, i figure out that the database should have been designed slightly in a different way. So i create or delete or modify few tables (sometimes more than few tables) for better optimization and data fetching.
So in my experience, i always have to do a rework somewhere in the mid way.
Below are the steps i follow for big applications.
Visualize the database. I prefer sketching them.
I have coded my own PHP MVC Framework and i use that.
Create unit tests (if required)
Do some optimization.
Code cleaning.
Deliver.
My question:
I was never taught programming. I learnt everything through mistakes and experiences and ofcourse Stackoverflow. Am i following the right pattern ? Or is there a better approach to avoid rework. I am sorry, my question might sound noobish, but i am seriously looking for some helpful advice.
This ended up waaay too long for a comment...
Take StackOverflow with a grain of salt. Yes, there are some very smart, well-written answers, however there are also many cases of 'blind leading the blind'. You generally don't ask a question on SO if you know the answer, and if someone gets a terrible solution to their problem, but it works and they don't know any better, they can mark it as accepted like anyone else. There are a lot of people on this site in the mindset "if it's accepted, then it must be correct" and that will bite them in the ass eventually.
Find someone in your field that you personally respect and ask them to look over your DB design/methodology in detail rather than posing vague questions on SO. Your process sounds just fine in the broad strokes you've outlined, but who knows what kinds of devils are hiding in the details.
If there are certain small portions of code you'd still like to be reviewed by internet strangers you can try CodeReview.StackExchange.com. CR questions on SO get closed faster than you can blink.
I think your steps are good. You may consider posting some of your working code for review to get experienced programmers' opinions on design, best practices, etc. There are also chat rooms with lots of active users who are specialists in specific languages, if you don't have an expert on hand.

Could I please get some help correcting my little beginners project?

This is my first time posting something like this. I'm a complete n00b at programming/php. I was trying to grasp all the tutorials out there and wanted to create a sort of framework to base projects off of for web db/applications. I came up with a few files for crud operations that I know must really be horrible code. I was wondering if I could get some advice in advancing this 'framework' to the next level. I'm not great at OO, but I understand the concepts, so I went more functional instead. I'm aware that the songs are gross, I don't need help recognizing that.
I would like some help on the database calls. I understand I should be using PDO (to help with injection), but I'm not sure how to convert this code to that structure. I also realize that at the least I should be using mysqli functions. Again, n00b.
I am also aware of validating and sanitizing data, but again, being so new to this, I don't know where to begin. Especially if I wish to keep it tight and small. The comments are funny from a programmers aspect, but hey, you work with what you got. I'm trying to grasp MVC and be able to tie in AJAX and templates/skins, but the crux of it is to work with databases.
I do like how there is one config file that works with all the other files, and how that results in small files for index, read and delete. The others get a little longer. Not that including files is makes me cool or anything.
I think I fail horribly at understanding MVC and structuring the project so that maintaining it and adapting it is easier. I also realize that there is a lot of html in those php files which is a no-no too. How do I fill in the gaps from what I do know (I know what every line of every file is doing) to what I should know.
The code can be found here (probably not sourceforge worthy, but I want to help others learn as I do).
https://sourceforge.net/projects/eleete/files/
Building such a thing takes a good amount of time, before you go doing so I would suggest looking into open source CMSs such as Wordpress to see if they would suit you better than putting in hours of work creating something yourself, the reason I say this is because to begin with you may think it won't be too hard to create one for yourself, but as you get into it you will realize there are many avenues that need to be explored in terms of security and features.
However, if you still want to build something the most important thing is to be creating reusable, and easily understandable code. For example if you want to create db entries for things like pages, you'll want to create functions to do so, to which you can pass variables such as titles etc. A good way to begin is to create functions for collecting data from your db, for example siteinfo() could be a function that returns an array full of site info. To make sure every file has access to such functions you will need a global file like functions.php for example which you will need to include in each of your other files.
Remember, building a framework is hard work, but if you do it properly and thouraghly you should increase your productivity a good amount - this is something you need to consider when building it, make sure you're not doing things in a roundabout way. Make it simple, make it reusable, and make it powerful.
First off, welcome to the community! I hope you find here people who are excited to bring your more into the programming fold. It's an exciting place to be.
I get the impression you're biting off quite a bit. I fear you're also under the assumption you can write the perfect program from the get-go, which is a flat-out myth no matter how long you've been in the industry.
As to the former observation, my recommendation would be to pick a simple problem and try to solve it. My favorite recommendation here are simple card games - blackjack, for instance. Dice games like craps also make for short, achievable, and interesting programs. The intent of these projects will be not to build a code framework as much as your skills in dissecting problems and turning them into a solution the computer can understand and solve for you- your code.
Starting small will keep you from getting overwhelmed early. Starting fun will keep you motivated through the inevitable snags that will tempt you to throw your computer out of a closed window.
All that said, we're still here to help! Specific questions to specific problems tend to get the best feedback here, as well as questions that demonstrate you've done at least some homework on your own in terms of trying to solve it. The Stack Overflow community will be happy to give you a hand up, but not a handout. Good luck!
You're going to be much better off using a clean, simple framework. As you're so new with this stuff, I'd recommend CodeIgniter for sheer simplicity and speed. It helps enforce the MVC framework you're not totally familiar with yet, has all the built-ins you're likely looking for, and has a decent community. Being a Zend guy, I should probably suggest that, but it's definitely not the easiest to get started with.
MVC and OO are concepts you really should learn well out of the gate before going forward. This tutorial rocks. There are dozens of MVC primers out there, but in essence it boils down to separating your data layer, view layer, and the like.
PDO is not necessary to be safe, you just need to escape your sql with Mysql_escape_string or the like. I'm actually not a fan of PDO due to the monkey wrenches it throws into debugging.
Since you're new, I'd also recommend Xdebug on your server for troubleshooting. It cuts down debug time immensely.
In my experience, unless you've had to fix the shortfalls in someone else's attempt at a framework, you won't really understand how to build one yourself.
One of the key qualities of any sort of API or framework is the concept of abstraction. In a nutshell, as you find yourself repeating code, look for where the repetition could be abstracted away. The trick about this when you're building a framework is to do it in an extensible, usable fashion so that you have pieces that build on each other. In other words, abstractions can hide other abstractions. For example, It's all very well to abstract away the job of assembling an SQL UPDATE statement from a list of fields, but why does the application page have to check the list of fields is correct? Put that behind another layer that can be taught what the valid fields are for a certain object.
Another key quality that comes up at this point is refactoring. The phrase "be prepared to throw the first one away" is sometimes bandied about in programming circles. What it really means is that you should always be open to the idea of re-writing code because you've thought of a better way to do it. Even if you have to rebuild the code that calls it.

Basic PHP entry exam

My boss just asked me to write a little test for people that are applying for a new PHP developer position here. Since this is the first time I've been told to do such a thing, I was wondering what you guys think the test should contain?
I was thinking about something like a simple PHP login system: I think it covers most of the bases, but if there is something better you can think of, please post it below!
Basically, what are your opinions on what a decent PHP programmer should know?
I suggest you read http://www.joelonsoftware.com/articles/GuerrillaInterviewing3.html which is a great guide about hiring programmers.
The essential point is: It's not so much about the test you give them, it's about putting your applications into a discussion so you can figure out if they are smart or not.
I'd probably break it down into two segments, a basic Q&A session about the job, with some PHP, SQL and basic (but always standards-compliant) HTML and CSS questions. Shamittomar has provided a link to a good set of PHP questions and I would highly recommend using them.
Once this part is done and their brains feel thoroughly warmed-up I would give them two tasks to do.
Write a basic script of your choosing, something that the business already uses that should only take a small amount of time to complete. You're hiring someone to write code, so they should be able to write basic PHP code fairly easily. Give them a blank computer with a clear history and tell them you'll be watching them, and after the test you'll be viewing what resources they use to get the problem sorted. Obviously, someone who can work his way around PHP.net to find whatever documentation he/she needs isn't entirely stupid.
Fix a fairly complex script that you have written, provided only with a basic specification, descriptions from you of what the script is to do and a broken script you have pre-prepared. My last boss used to do this by writing a script himself, taking a note of every mistake he made and adding them back in at the end; at least that way the code itself wasn't broken beyond repair.
I find this to be the best compromise between simply looking at examples of code they're written and giving a full Joel Spolsky style interrogation. Give an applicant this test and you'll more than likely find someone with the level of competence you require, or someone who really isn't far from what you need.
A good one I was asked is, could I explain the different between public, private and protected properties and methods.
If you want to go down the object-orientated questioning route, ask the candidate what's the difference between a function and a method.
Write a piece of code which contains errors and is not optimally written. It should contain multiple errors from all sections of programming. Like I mean all kinds of possible errors.
PHP programmers often have to adopt a project and that as fast as possible so they have to be able to spot errors and find optimization opportunities where needed.
If you need BASIC exam, I'd recommend:
http://www.w3schools.com/PHP/php_quiz.asp
You can also see how he would handle exceptions.

Video learning for database design

I'm trying to learn good relational database design (using mysql and php if that makes any difference). I've already done some database work, so I'm not totally clueless, but I suspect that my solutions may not have adhered to best practices for efficient searching, optimization, etc.
Can someone suggest a good set of videos on the topic? If you know something is superb or has really made a difference in your own learning, please post your suggestion. Prefer videos, but books (as long as they're not too huge) are ok too. But prefer videos.
Thank you
Well, I would be sooo happy if I could recommend some fine videos, but I can't think any of them. Especially in database design, which is quite a complicated topic, I will not recommend videos. The fastest way isn't the shortest all the time.
If you would like to get some theoretical introduction to the topic, I could recommend the classic Ullman-Widom - A First Course in Database Systems book. It's quite huge, but it contains information that you won't use. Anyway, it sums up the theory of database design on the first 130 pages and it's really nice to read. It wil help to get your SQL to a higher level, too. You can find some information about using databases with PHP, XML and so on.
Have a look at www.vtc.com - they have training videos on just about everything, including database design, modelling and optimisation for most platforms. Some of them are free to view online as well.

What would be a good sample project to ask a prospective programmer to code during the hiring process?

My understanding is that asking for a work sample is a good way to determine if someone has the skillset you are looking for, as some people just interview well. So I want to ask potential developers to write some sample code for me.
I'm looking for ideas on what kind of small project would be something they could do in an hour or two, and would show that they have a good grasp of OOP, good coding practices, etc. And what to look for once they finish - how to evaluate it fairly and usefully.
For context, I'm a small business owner, interviewing prospective developers, for PHP development on internal projects. I can code PHP but am not an expert (some of the work is refactoring code I've written to be better structured and consistent), and so I'm also looking for what to look for when evaluating the samples, given that I'm not a trained or super experienced programmer.
Especially for people who have done hiring of this type before and used this method.
I was also thinking I could give them some code to refactor, and see how they do on it. Has anyone ever given a refactoring test as part of the hiring process?
Clarification:
I'm not talking about coding during an interview. I'm talking about coding instead of an interview. For context the inspiration for this question came from this article in FastCompany about how work samples are better predictors of job success than interviews:
Why It May Be Wiser To Hire People Without Meeting Them
http://www.fastcompany.com/magazine/136/made-to-stick-hold-the-interview.html
I would create a not necessarily good application and embed some bugs. I would come up with some simple functionality to be added to the program.
Does the applicant find some bugs?
How does the applicant's code integrate into the existing code?
Does the applicant get stuck on something that doesn't really matter?
Does the applicant adapt to the coding standard of the existing code?
After this exercise, discuss the code with the applicant. This may be more valuable than the actual code.
NOTE: with regards to #bpapa answer I would make sure that problem is novel and obviously not to be used in production.
Personally I would refuse to do this when asked. An interview is one thing, and doing programming questions on paper to asses technical knowledge is fine, but actually writing some kind of application for somebody is billable and I wouldn't do it for free. Even if it only is supposed to take an hour.
I think you should focus more on what the person has done in the past, and ask technical questions that you know the answers to (since you said you have limited PHP knowledge and want a PHP developer).
I would heed Joel's advice that giving homework assignments for interviews just weeds out the best programmers (paraphrased from his book). The better programmers have a lot of options and so won't want to go through the exercise of a programming assignment. They just won't apply. That will leave you with the mid-competency people. Unfortunately, in my experience those are the ones most likely to try to look better than they are and if you aren't an expert yourself, the ones most likely to mislead you.
Here's an alternate option. Have them point you at some work they have already done. Not necessarily the code, but the site. During the interview, ask them questions about how they coded it. What data structures did they use? How were the classes or functions organized? What problems did they have to overcome?
Then as traditional programming questions in the interview that they could answer for you ont he spot. This way you can gauge their understanding and their syntax. The two don't have to be the same question.
If you are not an expert then I would suggest you be careful about trying to evaluate other developers. You should probably figure out a better way to assess the dev skills of someone else if you are not that comfortable with your own level.
I am not sure there is a good solution for you.
I'd make the coding samples very straightforward and not have it take an hour or two. Simple coding exercises that take a few minutes should be sufficient - combined with other discussions about best practices, frameworks, design questions, etc.
I like the problems at streamtech. They are pretty easy and can often be done in rather short time, but they show that the applicant is capable of structured thinking and translating this to structured code.
As for evaluation---I would use this as an opportunity to learn. Do the problem yourself first, then compare to the applicant's code. Look up any constructs that you don't know, then ask yourself which version is more obviously correct.
I think the best thing you can do is try to have a real expert sit in on the interview with you. Hire a third party if you need to. I'm not sure it's possible to be able to give a quality assessment of someone who is a more experienced developer than yourself.
The other thing to consider is that really good developers may pick up on the fact that they are more experienced than yourself, and if you indicate that you are one of the developers it may actually put them off (not trying to be offensive, I just mean in the context of you implying that you are not very experienced.)
Give them an address or such as a plain text file and ask them to create a simple script to turn it into XML. I used that once and it worked wonders.
If you want to test them on the spot, ask them to reverse a string. From an organisational standpoint, perseverance, determination and enthusiasm are just as important as being technically adept, IMHO.
Well, everyone seems to be discouraging the coding effort for an interveiw. I'll disagree with the disagreers. To answer your question--if you want an example of what to have them code--drop a simple calculator on the table in front of them and ask them to write a program to create the calculator virtually. Give them half and hour and see how far they get. Some may finish in that time.
Have you ever tried pair programming before? Two people sit down at one machine, they share keyboard and mouse, and talk about what they're doing as they go. I think this is absolutely the best approach, because it will, eventually (after everyone's panic subsides), really indicate how well you two work together.
If you're not a great programmer, this person should be able to teach you and put you at ease. If they're not that good, but you work together well, that might be more desirable than a brilliant but unpleasant person.
At the end of the session, just delete your work. No big deal.
I've never been a part of the hiring process... but in interviews I've done, I was asked once to implement a doubly linked list, and another to work out an algorithm, the classic, how many integer points within a given shape, in this case three points forming a triangle, once in O(n^2) and then again in O(n).
I don't think the way to do it is to make them program something, but to make sure they know how to figure it out. You give them a problem or ask them a question, and tell them to think out loud, and observe their thought process. This doesn't exactly show if they have clean code, but depending on the problem it gives you insight as to wether or not they know what their talking about.
Having a small, well defined task can help you take examine people on a level playing field with a relatively small investment of time on their part. You don't need something complicated to see what people can do.
In the past, I've asked people to write a small web application that exercises a few fundamental concepts. We keep the particulars of what the application is supposed to do really simple.
I would also try to avoid tasks that require a lot of supplemental knowledge (viz, don't ask them to solve a problem from your particular problem domain).
Edit:
Regarding "small, well defined tasks": What I try to shoot for is something that includes a very thorough description of some simple business logic as part of a larger programming task. For example, one of the programming assignments I've given in the past involves setting up a simple Java web application and implementing a few features. We made sure to describe thoroughly how the features were supposed to work to remove ambiguity. This was for a couple reasons:
The point is really to see if the candidate can build a simple application from scratch, not to see whether they can guess correctly about what we want.
If you define the task really well, you get to see more about how thorough someone is with the type of work that they're likely to be doing in a business situation.
We wanted something flexible enough to give to candidates at varying levels of experience.
I should note here that I think programming assignments are most effectively used to check for competency. If you give a really hard assignment, or one that isn't well-defined, odds are that you're not going to get results that tell you what you want to know (unless you're testing specifically for how the candidate handles difficult assignments or ambiguity).
I argree with bpapa about it being an interview instead of a test run, maybe instead consider asking some questions about how they would undergo certain talks to do with the programming...
I once had to sit a Visual Basic MCP exam at the end of which they didn't even bother to give me the result.
Happily though when I asked the question as to whether I would be given the result I was sitting at the Commit/Cancel screen.
So I hit cancel thanked them for wasting my time and walked out.
To answer the question:
For PHP, I think a shopping cart, address book and forum would be good projects. Those usually cover a wide spectrum of web-programming topics - sessions, registration, database, form processing and authentication.
Personally speaking:
It looks like you looking more of an architecture person than a coding guru. I wouldn't penalize the applicant because he cannot come up with the name of an obscure function or need to refer elsewhere. The key thing is that he has the initiative and know where to look (heaven knows how many times I need to look up PHP.NET). A good question for an architecture guy, IMHO, is to tell him you have a data-set, but you have three different ways of displaying them and each view has different operations. If his answer is just a gigantic SWITCH-CASE, then he may be the wrong choice.
Usually weak programmers does not understand recursion pretty well, that's from my observations as far as now, now this does not have anything to do with PHP directly and probably a recursive factorial or fibonacci series wouldn't be a big deal, but let's say to load a tree control with data from a database with some parent-child relationship might be a good sample.
Also as you're not an expert as you said, think off something you can handle confidently.
It usually depends on the language you are hiring for. For example, when I went and gave an interview for PHP, I was asked to write a blog script, using custom MVC framework, whereas when I interviewed for an opening as a JS dev, I was asked to code a certain plugin in jQuery. Its more dependent on you are hiring the guy for ultimately. You dont want to ask someone to write you a music recommendation engine and then have him work on a payments gateway processor.

Categories