Using the Full Text image as a Background image

I've often had customers that wanted to be able to configure a unique page for the background of each page on a site. Whether this is a good idea or not is irrelevant.

Here's how I do it.

Add the following text to the index.php file for the tempalte right before the </head> tag. .

$article = JTable::getInstance("content");
$article->load(JRequest::getInt("id")); // Get Article ID
$article_images = $article->get("images"); // Get image parameters
$pictures = json_decode($article_images); // Split the parameters apart
echo "<style> body {background: url('../" . $pictures->{'image_fulltext'} . $pictures->{'image_fulltext_alt'} . "');}</style>";

You may want to set a default background in the regular css file for the site so that no page will have a blank background.

To retrieve the URL of the intro image in a Joomla article

This code is taken from: http://www.eighttwentydesign.com/blog/all/149-how-to-get-article-s-intro-image-in-joomla-using-php

They provide a more detailed explanation of how to use this code. Note, I had to make one change from their original code to include a / character after the img src=' text.

<?php

// Article Image
$article = JTable::getInstance("content");
$article->load(JRequest::getInt("id")); // Get Article ID

$article_images = $article->get("images"); // Get image parameters
$pictures = json_decode($article_images); // Split the parameters apart
// Print the image
echo "<img src='/" . $pictures->{'image_intro'} . "' alt='" . $pictures->{'image_intro_alt'} . "'>";

?>

Multi-dimensional search in an array like a MySQL SELECT with WHERE AND AND AND

I never know when I should be going directly to the database to do a search and when I should search within a PHP array where I've already loaded the database data. Anyway, there are times when it's clear that searching an array is necessary and I like to be able to use a search which is essentially the same as an SQL query like:

SELECT `field_name` FROM table_name WHERE `field2` = 'something' AND `field3` = 'other' AND `field4` = 'another'

to do this I used the following function:

function searcharray2($value, $key, $value2, $key2, $value3, $key3, $array) {
   foreach ($array as $k => $val) {
       if ($val[$key] == $value) {
           foreach ($array as $m => $val) {
               if ($val[$key2] == $value2 AND $k==$m) {
                   foreach ($array as $n => $val) {
                       if ($val[$key3] == $value3 AND $k==$n) {
                           return $k;
                       }
                   }
               }
           }
       }
   }
   return null;
}

Problem with accented characters not showing up using PHP and MySQL

If your data is loosing its accented characters when you retrieve and store it in your database, try using the following command:

SET NAMES 'utf8'

PHP Age Check Function

 

This function is used to compare an age relative to a particular date (in this case July 1). It assumes the birthdate is being provided in the format 'dd/mm/year' but needs to be checked against 'year-mm-dd'.

function agecheck($birthDate)
{

$date = explode('/', $birthDate);
$birthDate = $date[2] . '/' . $date[1] . '/' . $date[0];
$age = floor((strtotime('2014-07-01') - strtotime($birthDate)) / 31556926);
return($age);
}