new to php - help needed with own project

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

new to php - help needed with own project

Post by barrowvian »

Hey all,
Pretty new to this forum and to fairly new to php in general. I have a lot of reading/video material to go through but thought I would post my overall goal in here for some support as to how difficult this would be to produce and what are the main focus areas to study. Very keen to get stuck into learning php – mainly just as a hobby.

I’ve been learning about php and mysql database connectivity so pretty comfortable with that now. I have a basic mysql table which contains the following fields;

Student_id primary key not null int 3
Course_name not null varchar 50
Attendance not null int 3
Grade not null varchar 3

Ive populated the table with some basic info to have a play around with; the info is as follows;

001 computing 100 1.0
002 computing 100 2.1
003 computing 50 3.0
004 sports 100 2.1
005 sports 80 2.2
006 sports 40 3.0

Please see my “very simple” design of what I’m looking to produce for my own personal project that I have set myself.

Image

What I want to do is have a variety of list boxes 1, 2a, 2, 3 and 4 which contain values of what can be related to that of the data within the database. For example, list box 1 would contain “computing”, “sports” and “all”. Box 2a would contain “>, <, = , >=, <=, between”. Box 2 would contain a value ranging from 10%, 20%, 30% ..... 80%, 90% and 100%. If the “between” option was selected from 2A then list box 3 would be visible and the user could select which values they want. I’d like to implement some validation here so that the user couldn’t select > 100% or between 40% and 30% (ie the larger of the two values would have to be in list box 3). Finally the user would select a grade to query from too. I would also like to have it flexible so that the user can make selections by not having to use all of the list boxes. For example, the user can select the course and the attendances, or the course and the grades – but they always have to select the course to query from.

After the selection process has been completed then I would like to display the data in area 5. It would just be based on the number of records selected. For example if the query was SELECT * FROM table WHERE course = ‘computing’ AND attendance = 100 then it would echo a statement along the lines of “there are ‘2’ records with this criteria”. If the option of “all” had been selected from listbox 1 then it would display both sets of results as though it had done a comparison between computing and sports.

I hope I haven’t made it sound too confusing. I realise that it probably way out of my league to create something like this easily but any help would greatly be appreciated. Im ideally looking for some pointers of what to look into, what kind of functions/statements I’d need etc etc. Anything and everything 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: new to php - help needed with own project

Post by califdon »

Most of what you described is really HTML and Javascript, so would be better posted in our Client Side forum, but the database aspects would be PHP code, so I'll leave it here. You described a fairly common kind of user form and display, perhaps best described as multiple criteria queries. It is not really too complicated, but you have to resolve several issues before you can begin doing any coding, including:
  • When the user inputs several different criteria (course, grade, and attendance), what is it you want to retrieve, the records that meet ANY ONE of the criteria, or only those that meet ALL of the criteria? It's the difference between using ORs and ANDs in the WHERE clause of your SQL.
  • Do you want the input screen to be replaced by a results screen or do you want to use AJAX technology to refresh the data on the same screen without reloading the page?
If you want to learn AJAX, too, that's fine, but understand that there's substantially more code, and certainly another PHP script involved. And you should have a good grasp of both HTML and Javascript in order to use AJAX.
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

Re: new to php - help needed with own project

Post by barrowvian »

Thanks Califdon for your reply. I agree that broadening my outlook as to how I want the results to be displayed will lead to solving a few probems.

Your first point: I want the sql to consist of AND's as opposed to OR's as I want some quite specific results. As for your second point - I'm ideally looking at focusing on one new language as a building block to open up new doors to other languages so I'll give the AJAX option a miss, for now. If I was to decide that I wanted to replace the screen then Im assuming that when I return to the query page that it will basically start over again and once submitted will once again display a results page? If I was to display the results underneath like in the diagram and I then selected new criteria from the boxes and hit submit would that overwrite the original query or return a error to me? Or is that getting back into the AJAX that you mentioned?

I hope my questions arent too confusing :-)
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

Re: new to php - help needed with own project

Post by barrowvian »

If anyone has any links to tutorials that may be useful to me then I'd greatly appreciate it, thanks
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

Re: new to php - help needed with own project

Post by barrowvian »

I have created this new topic in the client-side coding section that contains this project, but a very simplified area of it to allow me to build up my skills bit by bit.

viewtopic.php?f=13&t=86988
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: new to php - help needed with own project

Post by califdon »

barrowvian wrote:Your first point: I want the sql to consist of AND's as opposed to OR's as I want some quite specific results.
OK, that's fine. Some beginners don't immediately recognize the difference, but it sounds like you do.
As for your second point - I'm ideally looking at focusing on one new language as a building block to open up new doors to other languages so I'll give the AJAX option a miss, for now.
Good choice. You'll need more than one, but you can start with HTML, which you will need to understand thoroughly in order to use any of the others. CSS is essentially a part of HTML, but can be learned separately. HTML (and CSS) create a static web page, meaning that there is no user interaction, it just displays a fixed page. To detect and respond to ANY user activity, Javascript is required. Javascript is such an important part of most web pages that you definitely need to learn that as soon as you have a good grasp of HTML. These are all "client side" technologies, meaning that they are executed in the user's (client's) browser.

PHP language and MySQL database are "server side" technologies, meaning that they are NOT executed in the browser, in fact the browser should never see any PHP or MySQL code. It all happens at the server BEFORE anything is sent to the browser.
If I was to decide that I wanted to replace the screen then Im assuming that when I return to the query page that it will basically start over again and once submitted will once again display a results page? If I was to display the results underneath like in the diagram and I then selected new criteria from the boxes and hit submit would that overwrite the original query or return a error to me? Or is that getting back into the AJAX that you mentioned?
Setting aside AJAX, your assumptions are basically correct. Assume that you write a PHP script (call it "mysearch.php", for reference here) that generates HTML to display something like you illustrated. In the HTML there would be a <FORM ...> element and it would specify what server script will handle the request when the Submit button is clicked. Let's say you name the second script "myresponse.php". That script will be called when the user clicks the Submit button and the contents of all the <INPUT ...> elements of the Form will be sent to myresponse.php so that it can do whatever it is you want to do, such as look up data in a database, including sending a new page back to the browser. If you, as the programmer, desire to do so, you can send the same or a similar page back with the added data, and either with or without the Form to request another search. That's entirely up to you, as you write the PHP code.

It is also possible (and quite common) to combine scripts like mysearch.php and myresponse.php into a single script that contains conditional branches to determine which action is appropriate each time it is called, but I would suggest leaving that additional complexity until after you feel comfortable with doing it with two scripts.

The major point is that you have to have a very clear picture in your mind (better yet, on paper) as to what you want to happen, because it will only happen because you write the code to make it happen!
I hope my questions arent too confusing :-)
Not to me. ;)
Post Reply