April 23, 2006

MYSQL, PHP Code snipit

If you are a regular reader of this blog, you may want to just skip this entry. I am posting a php function I wrote this afternoon that solves a problem I could not find using Google. I often grab code off of other peoples posts or websites, so I thought I should "give back" so other people could benefit. I'm also curious if I get any hits from this....

The statement of the problem goes something like this:

Is there a quick and easy way to copy a whole row in a MYSQL table and copy it to the same table? obviously i want the ID to change to the next auto_increment value.

The solution is the following:

INSERT INTO the_table(column_list) SELECT column_list FROM the_table;

(ref: this link)

where column_list excludes the first "pk" element since we want it to autoincrement, The problem is that column_list could be quite long, and may not be fixed, so it needs to be created dynamically. Here's a PHP function to do the job:

// Makes a duplicate of a table row
// All fields are duplicated except the first slot pk field, which
// is auto-incremented to the next available value.
// You are probably going to have to "fix" the site_db.Conn stuff to match your setup.

function MysqlCopyRow2($TableName, $IDFieldName, $IDToDuplicate) {
            global $site_db;
            global ${database_.$site_db.Conn}, ${$site_db.Conn};
            mysql_select_db(${database_.$site_db.Conn}, ${$site_db.Conn});

        if ($TableName AND $IDFieldName AND $IDToDuplicate > 0) {
                $selectSQL = "SELECT * FROM $TableName WHERE $IDFieldName = $IDToDuplicate";
                $rstSelect = mysql_query($selectSQL, ${$site_db.Conn}) or die(mysql_error());
                if ($rstSelect) {
                        $column_list = "";
                        $row = mysql_fetch_array($rstSelect);
                        $RowKeys = array_keys($row);
                        for ($i=3;$i<count($RowKeys);$i+=2) {
                                if ($i!=3) { $column_list .= ", "; }
                                $column_list .= $RowKeys[$i];
                        }
                        $insertSQL = "INSERT INTO $TableName($column_list) SELECT $column_list FROM $TableName WHERE $IDFieldName = $IDToDuplicate";
                        $rstInsert = mysql_query($insertSQL, ${$site_db.Conn}) or die(mysql_error());
                }
        }
}

Here's a line of code to call this function (property is the table name, property_pk is the name of the first autoincrement field in my property table, and $oldPK is an integer that is the specific row you want copied.)

             MysqlCopyRow2("property","property_pk",$oldPK);

Good luck! It works for me.

March 16, 2006

New Religion

I like to think I'm open minded, but unfortunately, on some topics, it takes practically getting hit upside the head for a new idea to sink in. Over a year ago I wrote about my decision to stop eating anything with trans fat. A friend of mine suggested in an off line email correspondence, that that wasn't going far enough. I needed to stop eating sugar, anything with white flour, etc. Here's an excerpt (from 7 Oct 2004!):

ME:
> What's your thinking behind not eating sugar or flour or processed foods?
> Trans fat is, in a sense, poisonous, and is a no brainer. But why sugar
> and white flour? How are those bad for you?

STEVE:
I've researched health and nutrition pretty extensively - the
bottom-line thing that I've come up with is this: humans have evolved to
thrive on a certain diet - a natural diet.  The further away from that
you get, the more harmful the food is to our bodies.  We're not meant to
eat refined sugar or processed flour, just as we're not meant to eat
trans fat...

Personally, I made big changes in my diet in the early spring, and my
most recent bloodwork shows big increases in my health (e.g. blood sugar
down, triglycerides down big time, HDL up, LDL down, etc.).  The "big
changes" are: eating less trans fat, sugar, flour, processed foods,
sodas, etc.; eating more eggs, beef, ham, non-starchy vegetables
(including lots of nutrient-packed stuff like romaine and broccoli),
cheese, etc.  I'm also down about 10 pounds to my ideal weight of 175 at
6'0".

So how long did yours truly take to get on board? I started my new diet Feb 1, 2006. What did it take to convince me? A book I picked up in B&N called "Fantastic Voyage: Live long enough to live forever." Written by a very smart guy, Ray Kurzweil. He basically convinced me that if we can survive for another 30 years or so, then technology will be powerful enough to repair our bodies and restore our youth. I don't doubt that this will be possible in centuries, but he makes a very good case that it will happen quite a bit sooner than that.

This is in a sense, my new religion. It's an outlandish idea, and it requires faith. I have faith in this idea, and therefore, I have no other choice but to eat good food. The diet along with exercise, is the single most important thing you can do to make it.

So Steve, if you're reading this: Thanks for trying to convince my a year ago, but I was too pig headed to listen to you. I am now taking your advice!!

January 18, 2006

Dangerous Idea?

From the Dangerous Ideas part of The Edge....

No More Teacher's Dirty Looks

Well said sir!

October 03, 2005

great article about unschooling

Hopefully I won't get in trouble for posting a few paragraphs of this... to see the whole article go to:

http://www.salon.com/mwt/feature/2005/10/03/unschool/

click the button at the top to watch the advertisement, and then click another link to go to the article...

Endless summer

Unschooling is a radical branch of home-schooling where kids control what and when they learn -- free of teachers, schedules and tests. Unschoolers say it's intellectually empowering. Critics call it irresponsible.

By Sarah Karnasiewicz

Oct.  3, 2005  |

Celine Joiris has never failed a test. Never eaten crappy cafeteria food. Never been picked last during gym. It's not that she's a supernaturally lucky 16-year-old -- she's simply never been to school. "I like the idea of studying, but school is just like incarceration," she explains. Her brother Julian, 17, agrees. "My approach is, planning, schedules -- OK. Tests, OK. College, OK. Whatever. But I don't really want to think much about it," he shrugs. "I can't tell you where I'll be in two years."

What's that? A smart 17-year-old without a plan? A bright, middle-class teenager who's not stressing out about SATs and admissions essays? In an era when college prep begins in preschool and adolescents need Palm Pilots to manage their after-school activities, such nonchalance has the power to shock. What about all those stories about home-schooled kids dominating national spelling bees and hogging spots at Harvard? Surely "whatever" is not in their vocabulary.

But Celine and Julian Joiris are not your typical home-schoolers -- they are unschoolers, followers of a radical approach to education that rejects not just the routines of traditional school, but the authoritative ideology it represents. Unschoolers make up approximately 5 to 10 percent of all home-schoolers. They learn without teachers, curricula or exams; rather, their whole lives are laboratories in which skills and smarts are acquired piecemeal, through casual interaction with the world around them.

article continued online at the above link.

July 18, 2005

Real Estate School

What am I doing these days? I'm in real estate school! Why am I doing this? Several reasons...

  1. I always wanted to at least know what realtors know.
  2. I have just designed a commercial real estate web site, and my partners told me if I got my license I would have more ways of making money.

The best part about the school is the teacher. He's a local broker here in Tucson named John Barry. I think it's safe to say that, except for proctologists, realtors have the best stories. It makes the time go fast (5 hours a day, 5 days a week, for 4 weeks) for some pretty dry material.

The interesting thing about the class is the people in it. Almost all of them are trying to change their lives. I was talking to the lady that sits next to me... She had to quit her job as a property manager because they wouldn't let her take off for 4 weeks. So she has no job and a kid in daycare. But there is good news: She already has a job lined up. Her step dad wants her to take over his business. I told her, that's great! She said, "It makes me sick to my stomach thinking about it." She's scared she won't be able to live up to expectations.

I am starting the 3rd week this week. I'll try to jot down some of John's stories to post here later...

July 07, 2005

WYA with AC Men

My house has two air conditioners. This is because it has an addition that was built about 6 years ago (It's a one story house.) The second AC is bigger than the first, and the two thermostats are not very far apart from each other. This makes things complicated because if you turn one AC up, the other AC shuts off from the cold air of the first AC and one side of the house gets warm from adjusting the opposite thermostat! (When we moved in, I didn't have a clue about this, and it took me a while to figure out what was happening.)

Anyway, recently, one side of the house started getting warmer. It was annoying, but I figured I just hadn't set the two thermostats correctly. This situation kept getting worse, and I had to finally conclude that the old AC was giving up the ghost. So I called an AC man.

He came out a started taking wires off and hemming and hawing. He went to the outside unit and took it apart and took a sledge hammer and started tapping the compressor with his ear up to it. "This doesn't look good", he says. "I'll try one more thing" he says. He then takes out a humongous capacitor and hooks it into the circuit and turns the system on.

"Well," he concludes. "It looks like you need a new compressor. But if I were you, I would change out the whole unit, because the fan's not far off either." "How much?", Says I. "Oh about 1200 for a compressor or 2400 for a completely new unit."

He had me hook line and sinker, and I was fixing to say OK, but I remembered something. I just renewed my home warranty and it covers any problems with the AC. If I had remembered this before, I wouldn't have even called this guy. In any event, I told the guy that since it's so expensive, I was going to have to use them instead. So he puts everything back together and leaves. $70.

The home warranty people just sent over a guy yesterday. He added coolant to the old system and it is now pumping out cold air like there is no tomorrow. Morale: Watch Your Ass with AC Men. I wonder how these people can live with themselves.

July 06, 2005

Podcasts Kill Creativity

I was pondering the other day why I went from March to July without blogging. My immedate answer would be that I've had nothing to say that's interesting. But I think it's something else.

Most of my blogging topics came from my hour long walks.  For me, light exercise is very conducive to introspection and reflection. When I was in my blogging "heyday" I was using my cell phone's voice recorder to record little snips of ideas as they came to me on the walk. I would then replay them and flesh them out into posts when I got back home.

So what's different now? I'm still taking walks! The deal is that, since the first of the year, I've been listening to podcasts on my walks. Mainly Adam Curry and TWiT, but also, Jimmy Jett and The Nowhere Man. Those four alone do a pretty good job of monopolizing my attention.

The TWiT cast is an hour, but there's good information there and it's only once a week. Adam's cast is 40 minutes and usually every day. The other two are short 10 to 15 minutes and not everyday. So Adam, I'm sorry!  It's been fun, but I need my thoughts back<g>.

July 05, 2005

Dancing continues

Heather and I are still dancing, trying to get better. (For those of you reading this for the first time, we dance west coast swing exclusively.) Let me tell you, getting better in dance is a SLOW process. Two things work against you... first you need to practice with many women, and there ain't that many dances in a week. Two here in Tucson. Second, you can't see yourself, when you are dancing. So there's no feedback. The old school way of getting feedback is to take private lessons (which I am doing.) But I've also tried to attack this one with technology....ie, with video. Watching myself dance on video is excrutiating. While I'm dancing I think I must look cool, but when I watch the hard evidence on tape, I see how "novice" I look.

We just got back from a Phoenix 4 day swing dance convention. Heather and I both competed. Here's a video Heather took of me dancing in the competition. (We got busted for taking a video and had to stop before I could film Heather, unfortunately.) I am wearing bib number 595. We did not even make the first cut....sigh.

Download phoenix_jack_and_jill.wmv


July 04, 2005

winbar digg tracker that works

I've said in the past that I don't read newspapers because it's mostly all bad. If nothing bad happens close by, you can be sure that the reporters will find something, somewhere to serve you with your morning coffee. And once you've read the story, there's no way to get it out of your head. Why start your day on a downer? Or worse, end your day on a downer?

But I still want the good stuff, like the comet impact. So, I get my main news from a little program that runs at the top of my screen called Winbar. It will show the headlines from any site with a RSS feed if you have the proper "tracker file". I wanted to start monitoring Digg.com, and noticed that the tracker file did not work because of programming errors. I fixed them and here's a tracker that works for digg....

Download Digg.trk

March 21, 2005

Clearing my ears

I had the GREAT joy of figuring out how to clear the pressure from my ears on an airplane flight a few days ago!

Background: As long as I can remember, I've never been able to clear pressure off of my ears. Blowing into my pinched nose did something worse: it cleared one side and left the other pressured, which at one time in the distant past gave me a headache. So I stopped trying. My only strategy since then has been to chew gum, which is hit and miss and usually leaves my ears in bad shape, sometime for days afterward.

We are currently in Birmingham, Alabama, visiting the in-laws, and I was explaining to Sierra how to clear her ears on the flight over (her first plane flight.) She didn't get it, so I kept blowing into my ears over and over and on one try, I had the pressure on and I swallowed. Bingo, my other ear cleared. I couldn't believe it.

So here's the miracle cure again for anyone who may have this problem: Blow into your pinched nose AND SWALLOW! Joy Joy. Deep sea diving here I come.

April 2006

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            

Typepad People

  • Merlin Mann
    43 Folders is the digital parking lot for Merlin Mann’s OSX tricks, productivity hints, and assorted lifehacks.
  • Sex Kitten
    THE ONLY TRUTH I KNOW IS MY OWN!!
  • steve crandall
    I have a particle physics background and live happily with my wife Sukie and our four ferrets.
  • christian chambers
    give me free time, i'll be asleep in one minute
  • Cyn City
    Female web pseudo-n00b, photo/webcam/forum/blog junkie, exhibitionist.
  • Simply Divine
    Thirty-something and holding!