Archive for the ‘PHP and mySQL school project’ Category

ITC280 – brute-force nav page

19 August 2009

I wanted to do something special with “nav” (navigation).  The stuff on the left sidebar.

On a shopping site this usually contains a dynamically-changing set of links to help the customer find items of interest.

But that’s fancy code. I wanted something on the left that would submit specific queries of the user’s choosing. But the form of check boxes I had there, as cool as it was in its basic implementation, was not  doing what I wanted because I didn’t have time to work out all the code.

I had the form submitting the query arguments to the server in the form of a query string on the URL for the page named in the form’s “action” property, a page I called “art_choice”. This is pretty standard. But if you want the query to be reusable (in other words, the form settings to stay the same) after the first submit, you have to write extra code.  Any paging function takes the basic query and adds different limits to it as the user goes through the pages of results. Our pager had nothing built in to save a variable query statement. The query statment was fixed in the list include and would re-run every time a new page was chosen.

I looked on the net and in the text for different ways to deal with saving a variable query. I found the tech of Partial Page Rendering using inline frames and similar methods. The text goes over the use of the $_SESSION variable in PHP for this purpose. And it also mentions the simpler method of saving the data in hidden form elements.

I decided on an unconventional approach using hidden form elements arranged in a table. Each cell in the table would produce a different query result. I like the idea of “laying out all the choices” for a web user, though the concept has its limitations. I could have written code to build the table iteratively each time the page was called, but I didn’t feel like I had the time, so I just wrote out the whole table in HTML and filled each cell in with its unique query string. This works, as far as it goes, with just a little change to the “choice” page which the form buttons all call. I left in echos of some of the strings involved so I could see what was going on “behind the scenes.”  This does not include any paging – that was the basic trick. I got the query results down small enough so that none contained more than 6 records.

Total time, including study, about 5 hours.

ITC280 – continue re-org, upload, test

14 August 2009

I have spent roughly 10 hours since the last post getting my pages ready to upload to zephyr.

I spent a lot of time re-working the page list spreadsheet (in Open Office). I still don’t find the format totally satisfactory but it’s getting better. Where a specific include goes with a specific public page, it is listed on the same line with the page, and their purpose is described on one line. I also added a location column to keep track of paths.

I edited all my local pages for the zephyr path names. I don’t have different pages for use at home now. I just put both paths on the same page and comment the unneeded one out. Editing the paths for the Rich Text Editor is a real pain in the butt, though, and it doesn’t work yet, either at home or at school.

The first_data and admin_reset pages worked on zephyr after tweaking database names. MySQL at home seems to be set to ignore capital letters in table names (makes them small letters) so I’ll have to see if this solves anything at home with these pages.

Everything else seemed to be working, but I didn’t test uploading on zephyr, just at home, where it worked.

Also note that I don’t yet have a “contact us” form, though it is a link on my left sidebar. The right sidebar is just text at this point, while the left side is set up to send a query string to art_choice.php. This shows the top page fine, but if there are other pages they come up blank and error messages complain about a bad data array or somethnig like that.

There is a lot of code on the site now, and a lot of pages. Much of it was provided to us by Bill. I did work from home for this most recent upload and test. Zephyr is a public server and is available to anyone. The uploads require a secure FTP client (WinSCP in my case) but anyone can look at the public pages with a browser.

ITC280 – Adding more features, better org.

12 August 2009

I have not been keeping up this blog!

I have worked several hours on developing alternative search methods for large databases.  I created a database of 10,000 categories. I then created a grid – a table with 9 cells with a table with nine cells in each cell. These are to hold the category names at different levels of category in a certain pattern. I got a way of mapping the query results into the cells for controlled queries containing exactly 81 results (9×9).

Then I went back to the main application and got it fully organized and somewhat smoothed out then started working on passing query data from the left sidebar into the “list” page.

The organizing involved boiling down every public page that generates HTML (some don’t – only do redirects) into a little top section of notes and parameter selections and a little bottom section of includes.

Most of the public pages follow this exact pattern.

The path of the first include, the configuration include, has to be adjusted depending on your installation. This is a pain if you are testing the pages on more than one installation. Then the configuration file sets all the other default paths so you have to edit that file for different installations.

The connect include contains your user name and password for your database (in plain text!). This also has to be edited for each different installation (if it is different).

All the rest of the code and content generation is done in the includes (the php includes). This is a very regular pattern to adhere to.  So you do almost all you fiddling in the includes. TIME FOR CLASS!

ITC280 – boiling it down

3 August 2009

I spent a couple hours yesterday incorporating all the class features that were in my “new” pages into my “older pages. That’s mostly: list and view with paging and including database queries. Now my “original” design uses Bill’s style sheet and just has links on the nav panel, whereas the “alternate” design uses Liz Castro’s style sheet and has fancy forms in both side panels (they don’t do anything yet.)

I transferred these today to the school file server.

Next steps will include adding user-controlled queries and a secure “account logon” for purchases.

Bill is also talking about content management which is another major application of php and databases (such as on this site.)

ITC280 – versions and variables

1 August 2009

I worked probably about 4 hours today on my pages.

I thought I would be getting into fancy queries, but I discovered that I hadn’t gotten all the pages to work together properly.

Public pages:

So far the two major public pages are just lists of includes. You have to get those right.

Private (php) includes:

The includes create links back and forth between the two public pages, so you have to make sure those links are set right. I set the link value in a variable.


On top of that I have three versions of the site (soon to become two). If one version calls a page from another version, subsequent calls will fail.

My simplest version, using little-altered code from Bill, uses a different html style than my other ones (which use tables for some formatting). So when I exported that code to my other includes, I had to add stuff to put the “view” content into a “td” (table-data) tag. Then I went back and made Bill’s page work like that, too.

Code and “print” sections:

I found it very helpful in writing my includes to put as much logic and code as possible at the top, with strings that could vary assigned to variables. Then below that I would “print out” the page by switching to html mode and just using php to echo the variables in their proper places. If you build lists using “while” this practice has to be modified, but it’s still basically useful.

I like to have color, but besides that I am not paying a lot of attention to formatting. Once I got my generated views inside proper td tags, what I saw in the browser was okay with me.

ITC280 – my version of the paged list

30 July 2009

Today I spent about 6 hours turning the paged list sample code into somthing that would fill a table with thumbnails (I didn’t try putting them inside links – didn’t want to stretch my luck).

I chose a 2 by 3 format for my table, as it fit better in the cramped screen I was working on at school. It’s a little clunky but I’m happy I could figure out how to do it. It runs off a “position” variable that is calculated for each entry in the list based on the return from the modulo funtion on its record number.

I’ll probably try to figure out queries tomorrow.

ITC280 – repurposing

29 July 2009

Spent about 4 hours repurposing the system to list and view my art items instead of muffins.

  • Create artitems table on zephyr using phpMinAdmin.
  • Get list and view pages working at home (as includes).
  • Rename the thumbnail art images (I called them farts) so the logic will pick them up.
  • Put all the changed files on zephyr and get them working there.
  • Update my files list spreadsheet.

How simple you want your public pages to be depends a lot on how much code you want to write.

In theory you can have just one public page for each major theme in the site (there might only be one) and then fill in all the content dynamically from includes. In practice you will probably have some relatively static public pages that just get linked to from the site. They would probably open in a new browser window.

The idea of passing the ID of a chosen link back to the server via the GET array is weird to me.  But in http, the page request is the main way the client has to communicate to the server, so it is taken advantage of. Normally, I would think of sending all data that does not have to do with viewing a new page as a POST to the server. But what is the server going to do with it? It wouldn’t normally store your data anywhere, unless it is creating an account for you in its database.  Most of the data you send it must be acted on immediately or lost. It’s not like a phone call where you keep the caller’s attention until you both hang up. I’d like to make that distinction more obvious in a site. I don’t like technology that looks like it’s doing one thing while it’s really doing something else.

ITC280 – list and view

28 July 2009

List and view is the basic web technique for viewing data in a database.

I am hoping to someday move beyond this technique, as I consider it very primitive, and inappropriate for some schemas. But everybody has to learn list and view.

Our instructor gave us two very basic pages about “muffins” that we were supposed to get working and then re-purpose to our own theme. I spent several hours today getting them working.

I wanted to try them as includes, instead of public pages, but this took some work. There is some logic in the view page that inspects the data handed to it by the the browser when someone clicks a button on the list page. If the data is no good for some reason, the view page is supposed to kick the system back to the list page (called a redirect).

When I was editing this code I messed up this logic, and it took a while to restore it to proper working order. Then I had to decide what to do about the fact that my local (at home) list page is different than my school list page. I decided to replace the calls to these pages with a variable defined at the top of each page. So my pages at school use the file I need to use at school, and the one at home uses the other file. I’m sure there is a more elegant way to do this.

Now the plan is to build this functionality into my two working versions that display images of artwork instead of muffins. This has to be done real fast so we can move on to the next part of the system.

ITC 280 – the new includes

26 July 2009

PHP allows a web designer to create a web page using “included files.” This technique is used by programmers for other purposes. In web design what the designer basically does, using a php script, is tell the server to assemble a web page out of pieces he has created previously. Those pieces can also have php scripts in them!

I am working with 3 different versions of a single web page using these includes. And I am working with them both at home and at school. So I have to get the three systems working the same way in both places. This Saturday I spent about 7 hours doing this.

Relative paths becomes a big issue when you have so many different files. It is a good idea to make sure all your paths work before you spend a lot of time writing code for a page. The most important paths are saved as constants in a configuration include. Without that include file, nothing else in the system will work!

What happened is that bacause of differences in how the school server and my home server are configured, they treat some relative paths in different ways. I spent a lot of my time getting stuff to work on the school server that was working fine at home. Hopefully I undestand it well enough now that I will not make the same mistakes again.

To Bill

25 July 2009

Bill: I don’t have a hosting company; I have a server installed locally. So it was just an oversight on my part. After the first 2 hours I went into php.ini and turned on error reporting. I have had several opportunities to use it since that time, and also on zephyr.

However, my local host is not set up as a real public server, so it has no public_html folder and doesn’t mind be browsing into the root directory of the server. I added a public_html folder on my servcer to match zephyr, but my server let me put serveral other folders (includes and images) in the “private” area without any complaints.

On zephyr, however, I could not get any html-generated call to reach a file that was not in the public_html folder. I hope this is the way it is really supposed to work. So I had to modify my setup to put the images and css includes up in the public folder. The php includes work okay in the “private” area.