It’s like this – you’ve had this HP Laserjet 4M plus (insert your model here) networked for years and you’ve been printing with no problems in all that time until you buy a Mac. Now suddenly there are two copies of everything being spewed out and mountains of wasted paper.

Don’t go looking through the printer menus on the Mac it isn’t there. Go to your printer, take it off line. Hit the menu button until it says Printing Menu. Hit Item until it says Copies=2. Hit shift and +/- button until it says Copies=1 then hit enter. Put it back on line and if you don’t have an uncle called Bob then you should!

I was trying to write a MySQL stored procedure today that was crying out for the is_numeric function – the one that doesn’t exist. I wanted to select two different things depending on whether the value in a field was numeric or not.

Luckily trying to convert a non integer into an integer returns a 0 (at least in the version I am running it does). Hence testing for CONVERT(field_value,SIGNED INTEGER)>0 is pretty close to what I’d expect from the missing is_numeric(field_value). In my case it is good enough as I know that I am dealing with integers not decimals, and none of them are 0!

Job done!

NB: MySQL version 5.0.22.

What have you got me into Mark – how can you write eight random things you wouldn’t normally write on your blog on a blog as random as this? Well at least I can manage the random part OK!

1. My first full peel was of Superlative Surprise Major at Ss Peter and Paul Ewhurst, Surrey.

2. I’ve read Pride and Prejudice (Jane Austin) at least once a year since my Godfather gave me a copy in 1982 – I’d read my Mother’s copy a “Utility” paperback before that.

3. I hate playing Monopoly – and I have trouble spelling it too!

4. I know how to spell forward but have a tendency to type it without the first r.

5. I have an almost twelve year old black and white cat call Minstrel who isn’t as fat as he used to be – no where near as fat as the cat from Norway who got stuck in the doorway.

6. I adore Flanders and Swann, and Gilbert and Sulivan and can very well spot an allusion in the dusk with the light behind it.

7. I use Oxford commas sparingly; sometimes they are necessary to avoid confusion.

8. Recondite is the first word fully defined on page 922 of the Chambers Twentieth Century Dictionary 1959 revision, 1966 impression – and if that isn’t hidden: obscure: abstruse: profound. Don’t you just love a word for which the meaning is obscure?

We were ringing on five tonight as our tenor bell isn’t all that securely attached to its headstock! Just two bolts and those a bit wobbly and we weren’t going to ring it up to check the bolts inside!

Later at the pub we were thinking of thought provoking questions for the Year 2 children on their new portal (e.g. “What if vegetables had legs?”) – most of us have an interest in education (some teachers, some governors, some trainers and some mothers or all of the above!). I’m surprised one of the questions wasn’t “What if the Tenor had come unbolted while we were ringing?” but perhaps we had already covered that. The collapse of the Saxon arch was the most extreme consequence we came up with (and we were avoiding anything gruesome) the trajectory going through the tower wall and into the chancel roof…! That’s the arch described by Christopher Winn in I never knew that about England thus:

…three supreme Saxon arches built over 1000 years ago when Sussex was remote and savage. The chancel arch is the LARGEST SAXON ARCH SURVIVING IN BRITAIN, possibly the world, and an incomparably beautiful masterpiece.

Chances are of course that it would have gone the other way and taken out the 5 or just landed on the ceiling (which might bear its weight depending on the speed of fall) but that was less imaginative.

I’ve seen Kestrels before, and what might have been a Sparrowhawk having a feast in our back garden. Yesterday we were on the M40 and I saw several birds of prey. There was one Kestrel but the rest were larger, higher and a completely different shape – with a V shaped tail like some whales. I thought surely they can only be Kites that must be how they got their name.

Then I looked in my bird book only to find that it (published in 1981) has them only in Wales – so a long way from the M40. But the picture was the only one that fitted! So google for “Birds of Prey sighted in Oxfordshire M40″ and lo and behold Red Kite on Wikipedia. They are frequently sighted over the M40 between Oxford and Wycombe – exactly where I saw them!

This time round I decided that all that cutting and pasting of form tags into the php page (and their layout) was a waste of time so I created a couple of database tables to tell the template which fields to include. So given the form name the template creates the rest of the page.


<?php
$sql="select form_caption, update_file, ok_function, validate_function
  from schema_forms
  where form_name = '$FormName';
select field_name, field_type, field_caption, span_name, needs_validation, can_hide, select_sql, allow_blank,
	block_numbers, allow_decimal, allow_negative
  from schema_form_fields
  where form_name = '$FormName'
  order by field_number;";
if (!isset($link)) {
	include("connectioni.php");
}
if (!mysqli_multi_query($link,$sql)) {
	echo "<p>" . mysqli_error($link) . ". Unable to load property list.</p>";
}
else {
	do {
        	if ($result = mysqli_store_result($link)) {
			$finfo = mysqli_fetch_field($result);
			if ($finfo->name=="form_caption") {
				$row=mysqli_fetch_array($result, MYSQLI_BOTH);
				$FormCaption=$row["form_caption"];
				$UpdateFile=$row["update_file"];
				$OKFunction=$row["ok_function"];
				$ValidateFunction=$row["validate_function"];
			} else {
				?>
				<p class="popuptitle"><?=$FormCaption?></p>
				<form name="<?=$FormName?>">
				<input name="UpdateFile" value="<?=$UpdateFile?>" type="hidden"/>
				<table class="popuptable">
				<?php
				while ($row=mysqli_fetch_array($result, MYSQLI_BOTH)) {
					$FieldName=$row["field_name"];
					$FieldType=$row["field_type"];
					$FieldCaption=$row["field_caption"];
					$SpanName=$row["span_name"];
					$SpanCaptionName=$SpanName."caption";
					$SpanInputName=$SpanName."input";
					$NeedsValidation=$row["needs_validation"];
					$CanHide=$row["can_hide"];
					$SelectSql=$row["select_sql"];
					$AllowBlank=$row["allow_blank"];
					$BlockNumbers=$row["block_numbers"];
					$AllowDecimal=$row["allow_decimal"];
					$AllowNegative=$row["allow_negative"];
					if ($FieldType!="Hidden") {
						echo "<tr>\n";
						echo "<td class=\"popuptable\">\n";
						if ($CanHide=="Y") {
							echo "<span id=\"$SpanCaptionName\">";
						}
						echo $FieldCaption;
						if ($CanHide=="Y") {
							echo "</span>";
						}
						if ($NeedsValidation=="Y") {
							echo "<span id=\"$SpanName\"></span>";
						}
						echo "</td>\n";
						echo "<td class=\"popuptable\">\n";
						if ($CanHide=="Y") {
							echo "<span id=\"$SpanInputName\">";
						}
					}
					switch ($FieldType) {
					case 'Hidden':
						echo "<input name=\"$FieldName\" value=\"".$$FieldName."\" type=\"hidden\"/>";
						break;
					case 'Text':
						echo "<input class=\"popmeinput\" size=\"15\" name=\"$FieldName\" value=\"".$$FieldName."\" type=\"text\"";
						if ($NeedsValidation=="Y") {
							echo " onKeyup=\"$ValidateFunction();\" onblur=\"$ValidateFunction();\"";
						}
						if ($BlockNumbers=="Y") {
							echo " onKeyPress=\"return blockNonNumbers(this, event, $AllowDecimal, $AllowNegative);\"";
						}
						echo "/>";
						break;
					case 'Textarea':
						echo "<textarea class=\"popmeinput\" name=\"$FieldName\"";
						if ($NeedsValidation=="Y") {
							echo " onKeyup=\"$ValidateFunction();\" onblur=\"$ValidateFunction();\"";
						}
						echo ">".$$FieldName."</textarea>";
						break;
					case 'Password':
						echo "<input class=\"popmeinput\" size=\"15\" name=\"$FieldName\" value=\"".$$FieldName."\" type=\"password\"";
						if ($NeedsValidation=="Y") {
							echo " onKeyup=\"$ValidateFunction();\" onblur=\"$ValidateFunction();\"";
						}
						echo "/>";
						break;
					case 'Date':
						$FieldNameD=$FieldName."D";
						$FieldNameM=$FieldName."M";
						$FieldNameY=$FieldName."Y";
						echo "<input class=\"popmeinput\" size=\"1\" name=\"$FieldNameD\" value=\"".$$FieldNameD."\" type=\"text\"";
						if ($NeedsValidation=="Y") {
							echo " onKeyup=\"$ValidateFunction();\" onblur=\"$ValidateFunction();\"";
						}
						echo "/>";
						echo "<select class=\"popmeinput\" name=\"$FieldNameM\"";
						if ($NeedsValidation=="Y") {
							echo " onChange=\"$ValidateFunction();\" onBlur=\"$ValidateFunction();\"";
						}
						echo ">\n";
						echo "<option value=\"\"></option>\n";
						for ($i=1; $i<=12;$i++) {
							if ($i==$$FieldNameM) {
								$Selected="selected=\"selected\"";
							} else {
								$Selected="";
							}
							echo "<option $Selected value=\"$i\">";
							echo date("M",mktime(0,0,0,$i,1,2000));
							echo "</option>\n";
						}
						echo "</select>";
						echo "<input class=\"popmeinput\" size=\"2\" name=\"$FieldNameY\" value=\"".$$FieldNameY."\" type=\"text\"";
						if ($NeedsValidation=="Y") {
							echo " onKeyup=\"$ValidateFunction();\" onblur=\"$ValidateFunction();\"";
						}
						echo "/>";
						break;
					case 'Select':
						echo "<select class=\"popmeinput\" name=\"$FieldName\"";
						if ($NeedsValidation=="Y") {
							echo " onChange=\"$ValidateFunction();\" onBlur=\"$ValidateFunction();\"";
						}
						echo ">\n";
						if ($AllowBlank=="Y") {
							echo "<option></option>\n";
						}
						if (!isset($link2)) {
							include("connection2i.php");
						}
						if (mysqli_multi_query($link2,$SelectSql)) {
							do {
						        	if ($result2 = mysqli_store_result($link2)) {
									while ($row2=mysqli_fetch_array($result2, MYSQLI_BOTH)) {
										$ExistingFieldName=$row2[0];
										if (isset($row2[1])) {
											$ExistingFieldID=$row2[1];
											if ($ExistingFieldID==$$FieldName) {
												$Selected="selected=\"selected\"";
											}
											else {
												$Selected="";
											}
											$ExistingFieldID='value="'.$ExistingFieldID.'"';
										} else {
											unset($ExistingFieldID);
											if ($ExistingFieldName==$$FieldName) {
												$Selected="selected=\"selected\"";
											}
											else {
												$Selected="";
											}
										}
										echo "<option $Selected $ExistingFieldID>$ExistingFieldName</option>\n";
									}
						        	 	mysqli_free_result($result2);
						       		}
							} while (mysqli_next_result($link2));
						}
						echo "</select>";
						break;
					}
					if ($FieldType!="Hidden") {
						if ($CanHide=="Y") {
							echo "</span>";
						}
						echo "</td>\n";
						echo "</tr>\n";
					}
				}
				?>
				<tr>
					<td class="popuptable">
					<span id="aOK"><a class="popuptable" href="#" onclick="<?=$OKFunction?>">OK</a></span>
					</td>
				</tr>
				</table>
				</form>
				<form name="OnloadForm">
				<input name="OnloadFunction" value="<?=$ValidateFunction?>();" type="hidden"/>
				</form>
				<?php
			}
        	 	mysqli_free_result($result);
       		}
	} while (mysqli_next_result($link));
}
?>

Then he tells me that there was probably a tool out there that would have done it for me! So then you just need to set the variable $FormName, include this file and write the appropriate Javascript validation function. I Ajax the lot into a floating box in the middle of the screen (pretending to be a modal dialogue box).

I’ve got off pretty lightly when it comes to making costumes so far. My sister’s children had been angels in the past so last year was OK. The sheep for the class assembly came out of a friend’s nativity collection, etc.

This year the dragon (of bad luck) is to be a sheep – luckily Asda have sheep in his size so that was OK – especially as they need to crawl in the costume!

But the angel needs to be a shepherd! I finally unearthed an old fashioned (stripe down each side) dish cloth and her ballet head band for the head dress but then there was actual sewing to do. My shirt wasn’t long enough so one of Daddy’s old ones with over half the sleeve cut off has been pressed into service. I don’t think that shepherds are known for being particularly smart so I didn’t feel the need to hem the sleeve. I then made the belt out of strips of the remaining sleeve sewn together then folded into a flat tube and sewn ip the side to stop it unfolding.

I haven’t found a walking stick yet!

Having struggled in the past to upload sourcecode using the pre and code tags and then still having to fiddle it is great to now have this simple method posted in the WordPress news section . I was so excited so I decided I had to blog about it.

My excuse for using it is a slight amendment to my January post on running queries against a MySQL database via PHP. I was finding that if I had a text field it was hard to see where one record ended and the next started.

Record1 Short data Other data And here is a cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Can you see what it looked like before? It isn’t easy to see where one cell starts and the next finishes is it?
Record2 Short data Other data Particularly if there are loads of fields in the output. This by the way is another cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Shall we look and see what it all looks like with the alignment changed?

Just do this when looping through the records instead:


					while ($row = mysqli_fetch_row($result)) {
						echo "<tr>";
						for ($counter = 0; $counter &lt; $numcols; $counter++) {
							echo "<td valign=\\"top\\">". $row[$counter] ."</td>";
						}
						echo "</tr>";
					}
Record1 Short data Other data And here is a cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Can you see what it looks like now? Is it easier to see where one cell starts and the next finishes?
Record2 Short data Other data Particularly if there are loads of fields in the output. This by the way is another cell with loads and loads on stuff written in it trying to look like the output from a text field in my database query. Not much of a change of code but I’ve found it much more readable particularly when looking to check what the body of a stored procedure does!

I’m impressed, I blogged about playing Mornington Crescent on Kyte TV last night and in fifteen minutes Jason from Kyte had commented letting me know how to embed the channel in the blog. Thanks for the swift response and here it is:

We have just concluded the inaugural game on the Mornington Crescent channel on Kyte TV. It was a tight game. Not sure when the next game starts but it is likely to be fun.

Next Page »