08 January 2008

At long last, PHP capitulates!

YES! I DONE IT!! HA HA HAHAHA!!!

I can now make PHP convert timestamps in obscure (read: retarded) formats into widely-used and sensible ones. The Saga of the Three Scripts (that began here) is drawing to a close! The third script, the writing is done!


Let us not speak of debugging just yet. I must first bask. :D

... umm, and pay no attention to that big chunk of data I completely forgot to account for, either. o.O I'm done, dammit! DONE!

...

*whimper*

10 comments:

Anonymous said...

I actually just removed timestamps from my site - leaving just datestamps. But PHP is a pain, it's like trying to untangle a wad of Christmas lights.

Random Michelle K said...

Hoorah!

I spent a good chunk of this fall learning php and mysql, so I completely understand where you're coming from.

I ended up with your books, most of which are useful. Although just trudging through my project was the most useful.

If you're interested in pooling knowledge--lemme know. :)

MWT said...

But PHP is a pain, it's like trying to untangle a wad of Christmas lights.

Hahaha... that's exactly how it is. Nice way to put it! :)

Michelle: Sounds like our falls were basically the same. ;) But I'm not using any books - I'm using a friend of a friend named Randi Mitchell, the online PHP manual, and the #php IRC channel on freenode.net (in decreasing order of helpfulness). Comparatively, PostgreSQL is incredibly straightforward and easy to understand.

Random Michelle K said...

I used that online php manual, but only as a last resort if I couldn't find what I needed in my books.

I tend to learn better by example, so I found it easier to take the examples and exercises in the books, deconstruct them, and then reconstruct them for my project.

Well, I also occasionally picked the brains of my husband and a co-worker, but mostly I did best with just me, my books, and the code. (Otherwise I tended to get solutions,but not necessarily explanations.)

Hmmm PostGRESQL looks interesting, but I'm not sure I'm up to it right now. (My next major project is all lined up as soon as my boss gets the new software in.)

MWT said...

Yeah, that online manual as a last resort is a good idea. Usually it just makes things worse. ;) The PostgreSQL manual has lots and lots of good examples, which is a large part of why I find it much easier.

What's your next project? I'm still in the middle of the first one, because after I finish getting this third script working, I have to actually use them to put data into the database, and that'll be a scary step. o.O

Random Michelle K said...

Well, my php project is done--the database works and does almost everything I want, and the thing it doesn't do I'm not sure it's possible *to* do, so I'm not worried about it.

I thought about starting another database project, but decided to give my brain a rest.

My next big project is 100% work. (my book database was created so I could learn php to support it at work. But the database was entirely mine.) I have to become comfortable with--and then revise all our documentation--for Dreamweaver CS3, Photoshop CS3, Adobe Acrobat 8, and the latest version of EndNote.

Jealous, aren't you? (laugh)

Of course that's for *after* we survive the first week of classes. Next week is pretty much going to be sitting at the desk answering questions and resetting passwords.

MWT said...

Ooo... documentation maintenance. I'm positively green with envy!

What was the one thing you couldn't get it to do? (Because of course now I want to know if I can think of a way...)

And what's your job, IT something at a university?

Random Michelle K said...

I'm a freak, because I love writing documentation. I think he helps my writing in general, so that's a Good Thing.

And I do software support and education for faculty, staff and students at the Health Sciences Center at my university. It's actually a lot of fun, because most people are really nice.

The problem I ran into with my php/mysql *seemed* like it would be relatively easy to solve, but nothing worked.

I have a database with three tables: books, authors, and genres. (There's a one-to-many relationship between the books table and the authors/genre tables)

When I add a book, I have the form set up so that I can add additional author fields--up to ten--at the click of a button.

What I wanted to do was to automatically generate the query based upon the number of last name author fields.

Unfortunately, I can't get any of the if statements or while statements I used to generate other recurring items to work in my query.

So this:
// create short variable names
$a = 1;

if (isset($_Post['LastName' . $a]))
{
WHILE ($a < 10)
{
$FirstName . $a = trim($_POST['FirstName' . $a]);
$LastName . $a = trim($_POST['LastName' . $a]);
$a++;
}
}

works to generate the variable names for me, I can't get it to work with the query to create this:

$query2 = "INSERT INTO authors
VALUES ('$ID', '$LastName1', '$FirstName1')";

$result2 = mysql_query($query2, $conn);

if (isset($LastName2))
{
$query2 = "INSERT INTO authors
VALUES ('$ID', '$LastName2', '$FirstName2')";
$result2 = mysql_query($query2, $conn);

(and so on and so forth)

I even tried doing it without variable names and just using the $_POST[''] option, but no dice.

But since I was limiting the number of authors a book could have anyway, I decided I'd wasted FAR more time trying to come up with a if then or while or if while or whatever statement that would create the code than it would ever take the write the damned code myself.

Oh here's the databased:
http://klishis.com/Books/database/search.php

e-mail me if you want to log in to look at the admin functions where you enter, edit and delete books. For obvious reasons I've got those hidden. :)

MWT said...

Have you tried empty() instead?

For example:

if(empty($cdom)) {break;}
else {
$cdomquery="insert into cdom values (nextval('cdom_cdom_id_seq'),$cdom, 'volts', $cdomsensor, $locus_id->last_value)";
pg_query($dbconn, $cdomquery);
}

or alternately

if (!empty($cdom))
{
$cdomquery="insert into cdom values (nextval('cdom_cdom_id_seq'),$cdom, 'volts', $cdomsensor, $locus_id->last_value)";
pg_query($dbconn, $cdomquery);
}

Random Michelle K said...

hmm....

I'll have to try something like that next time I pry it open.

(scribble scribble scribble)