Tuesday 30 June 2009

Websiting and ponding

I spent nearly all this morning trying to work out why something on my website wasn't working properly. Eventually I tracked down part of the problem - I had a mysqli->multi_query($sql), and when specifiying the final SQL statement before the multi_query was executed, I had put $sql = 'blah blah...'; instead of $sql .= 'blah blah...';. So the none of the SQL statements before the final one were actually being executed.

But after fixing that, it still wasn't working. Eventually I tracked this down to my string replacement statement. What I was trying to do is rename a file when the title/Headline of the image had been changed, as I include the headline as part of the image filename. So I had
$filename = str_replace("$oldHeadlineForFileNames", "$headlineForFileNames", $d['f']); ($d['f'] is the current filename, $oldHeadlineForFileNames is the current headline, and $headlineForFileNames is the new headline).

So, for example, an image with a headline of 'hello' might be named 1-hello-640x480.jpg. If I then changed the headline to 'goodbye', I wanted to rename the image to 1-goodbye-640x480.jpg. The problem with my replacement code above is that if an image didn't have a headline, then I wanted to add one, it wouldn't work. The code when the variables are evaluated would basically look like:
$filename = str_replace('', "my-new-headline", $d['f']);
Which obviously won't work since it can't replace nothing with something. I had the same problem in my SQL query that updates the database with the new filename as well. So I just changed it to
$filename = str_replace("-$oldHeadlineForFileNames-", "-$headlineForFileNames-", $d['f']);
and the SQL to
$sql = "UPDATE img_dimensions_save
SET filename = REPLACE(filename, '-$oldHeadlineSQL-', '-$newHeadlineSQL-')";

and now it works properly.



In the afternoon and evening I just did some more work on my photo website. Then from about 8.00pm-9.30pm I did some more work on the pond in the garden. I did some more website stooef, then went to bed about 11.30pm.

The weather was very hot again, mostly sun with a couple of patches of cloud.

Food
Breakfast: Bowl of Frosties; cup o' tea.
Lunch: Ham with mustard, crispy salad and sliced cherry tomatoes sandwich; banana; Rocky; cup o' tea.
Dinner: Slice of ham quiche; cous cous; salad; Caesar salad dressing. Pudding was a pancake with heated golden syrup and banana slices. Coffee; Green & Black's Maya Gold.

No comments: