PHP/MySQL Output In Two Columns, Newspaper Style

OK – here’s another dilemma that I searched the web high and low for, and couldn’t find a solution, so I made it myself.

My dilemma was that I wanted to query a MySQL table and write the first half of the output in one column, and the second half in an adjacent column. For example, say my table has 65 records in it – I want to print records 1-33 in the first column, and 34-65 in the second column. Everything I found had the output with all odd numbered records in the first column and all the even numbered records in the second column. Like:

1 2
3 4
5 6

I wanted:

1 4
2 5
3 6

Here’s how I wrote the code:

echo(“<table cols=3 border=0>\n”); // create main container table
echo(“<tr><td valign=’top’>\n”);
$sql=mysql_query(“SELECT blah1,blah2 FROM blah3 ORDER BY blah1″);
if ( $leftover == 1 )
$half+= 0.5;
echo(” <table cols=1 border=0>\n”); // create table within the outer table left-hand cell
while ($result=mysql_fetch_array($sql)) {
if ( $i >= $half ) {
echo(“</table>\n”); // close the left-hand cell table
echo(“</td><td width=25> </td><td valign=’top’>\n”); // close the outer left-hand cell, put in a filler cell for space, and open the outer right-hand cell
echo(“<table cols=1 border=0>\n”); // create table within the outer table right-hand cell
$half=999999999; // make sure half will now always be greater than $i
echo(” <tr><td>$blah1</td></tr>\n”);
echo(” </table>\n”); // close table within the outer table righ-hand cell
echo(” </table>\n”); // close outer container table

Note that if you copy/paste this code, WordPress likes to make “smart quotes” with the left hand quote symbol being different from the right hand quote symbol. Make sure all your double quotes are really double quotes and single quotes are really single quotes.

Another Solaris item learned

After spending many hours, literally, in trying to figure out why a cron job wasn’t running, I finally stumbled upon the answer. Since this blog is more often than not used as my memory stick (the ram in my brain is beginning to fail), I thought I’d explain the issue and the solution I found.

We recently upgraded a server from Solaris 8 to Solaris 10 using LiveUpgrade. Not a bad way to do things, if you ask me. Once the server was brought up in Solaris 10, one of my users’ crontabs stopped working. In this case, it wasn’t critical, but it was a real pain to catch up what the cron missed (after being gone from the office for 2 weeks.) I tried all kinds of things (except the ones that put me on the path to recovery) including adding test entries to the crontab and seeing if they’d run. They didn’t.

Off to Google I ran. I discovered that our servers are logging cron runs (the log files reside at /var/cron/log), and I hadn’t thought of looking at them until about 15 minutes before the epiphany. I went to set up the servers to log cron runs, because most servers are installed without cron logging. I discovered it was turned on. So, I checked the logs, and found that I was getting the error

! bad user (username) Wed Jul 21 13:38:00 2010

The user is valid, so back to Google. The first answer I found said that you probably have a problem with the user in /etc/passwd or /etc/shadow. The user was in both files, but had been locked using “passwd -l username” – This did not cause any issues in Solaris 8, but once we turned up Solaris 10, the cron jobs ceased running.

The bottom line that I found with this problem is that in Solaris 10, the new security will not allow a user with a locked account to run cron jobs. I assigned a regular password to the user and life is grand once again.

Thunderbird Software Update Failure

I use open-source software on my laptop. I don’t have Microsoft stuff loaded, except for the operating system. I don’t like Microsoft.

Ok, that’s out of the way. 🙂

I use Firefox for my browser and Thunderbird for my e-mail. They both work very well, 95% of the time.

Today, Thunderbird performed an “auto-update”, which is a good thing to do, so you can have the latest operational and security features in your applications. Today’s update failed, and put me in a perpetual loop, such that I couldn’t start Thunderbird and get to my e-mail. This is the second time I’ve experienced this problem. So, I didn’t panic this time. 🙂
[

SSH Requiring A Password

If you have gone through the process of sharing keys on various machines, but ssh is still asking for a password, I have the answer. After much pain, agony, wailing, and gnashing of teeth, I have found the elusive yet surprisingly simple answer. Change to your home directory, then issue the command

ls -ld . (that’d be ell ess space minus ell dee space dot for those who really shouldn’t be typing on a unix box)

If your directory does not come back as drwxr-xr-x (or 755 to those of us in the know), this is probably why your password is being requested. Change your home directory to 755 and try again. Happy?

This just in – your .ssh directory must be drwx- – – – – – (or 700) as well as the above info.  (My directory listing isn’t printing correctly – so I’ll write it out – drwx followed by 6 dashes.)

The Future Of Your Bandwidth

OK – for those of you who are not currently heavily involved with the internet, you still need to pay attention.

Comcast has recently announced that it may soon be implementing a bandwidth limit on their residential customers. See this link for details. If you don’t think this affects you, let me help you understand how this will affect you.
[

“Real” MS Vista Admin Account

Do you hate Micro$oft Vista as much as I do???

I know people who love it, but I can’t stand how M$ is trying to protect me from myself!  Anyway, my buddy from work did all the Google legwork, and discovered a cool tip.  [Read more →]

A “Sudo” Tip

I got this from a co-worker who pointed me to a website. Thanks go to Peter Leung who posted this originally at

sudo hacks: making cd and redirection work

[

Images In WordPress Not Appearing

This page last updated 17 May 2008

I’ve just spent about 2 hours troubleshooting an image issue with WordPress that apparently only happens with FireFox. I am currently using version of Firefox at the time of this writing. [Read more →]

Working late on a Friday

OK – here’s some geek speak that someone may be able to learn something from.

The servers I work on are primarily Sun servers. I have a Sun 3320 array that I’ve populated with 6 72-gig disks. We got 6 more in, and so I spent over a week trying to get them to be visible to the o/s. I eventually had a Sun tech come out and help me out. Here are the items that we causing my dilemma:
– We have the scsi array chained off our internal scsi bus – with the extra 6 disks, we’ve probably overloaded the scsi bus
– We have a 6 foot scsi cable connecting the server to the array (when a 12-inch cable would do just fine). The extra length is probably causing some of the problem
– The real culprit – I saved for last. The six new drives I loaded were not compatible with the original six. The first six have a spin speed of 10k RPM, and the six new disks have a spin speed of 15k RPM. I found out that the two different speed disks cannot be populated in the same array.

There was a week of work, frustration, late hours wasted due to lack of documentation about mixing spin speeds in a disk array. Who knew?

The Geek In Me

Hi, my name is Steve and I’m a geek. Is there a 12-step program for me? No, really, I like being a techie. I work at a job where I manage Solaris servers, databases (I prefer MySQL), and write web pages. I do web pages as my business, as well. I like to code my pages in PHP (that’s a web programming language) and have them talk to MySQL databases.

Someone once asked me what I used to create my web pages. My answer? vi. Google it if you don’t know what it is. I’m a geek!