Bectin
  1. You are here:  
  2. Home
  3. Random Insights
  4. PHP

Joomla Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in \libraries\joomla\database\driver\mysql.php on line 464

If your receive this warning when programming in PHP/Joomla, it's because you're expecting a result from a query that doesn't generate one. For example,

$result = $db->loadObject();

Remove this line and the warning goes away.

array_unique on a Multi-dimensional array

If you want to accomplish essentially the same thing as a array_unique but on a multi-dimensional array

$results = array_unique($results, SORT_REGULAR);

Referencing an object variable that has a space in its name

If you've got an object that has variables that have a name with a space in it (such as when the variable has two words in the name), you can't access it with the usual syntax.

For example, normally you can use:

Student->Name

but if the field is "First Name" and not just "Name" then you have to use different syntax.

Student->{'First Name'}

PHP Form calls itself

When a form is created, it is generally assigned an action which determines what happens when the form is submitted. If the action is left blank, then the form will call itself by default.

    echo '<form action="" method="POST">'.

An alternative method is to use

    echo '<form action="' .  $_SERVER['PHP_SELF'] . '" method="POST">'.

however, this doesn't work when used within the context of a Joomla extension so use the first method.

The form is essentially broken up into to segments; the form segment and the processing segment. In order for the form script to determine which part of the script it is supposed to be acting on, you can check to see if $_POST['save'] has been set.

if(!isset($_POST['save'])) // form has not been submitted

Sort multi-dimensional array based on secondary index field

This code is taken from http://php.net/manual/en/function.asort.php

The function works well but looses the original array indices.

function aSortBySecondIndex($multiArray, $secondIndex)
// sorts array by the specified index name
{
    while (list($firstIndex, ) = each($multiArray))
        $indexMap[$firstIndex] = $multiArray[$firstIndex][$secondIndex];
    asort($indexMap);
    while (list($firstIndex, ) = each($indexMap))
        if (is_numeric($firstIndex))
            $sortedArray[] = $multiArray[$firstIndex];
        else $sortedArray[$firstIndex] = $multiArray[$firstIndex];
    return $sortedArray;
}  

  1. Finding Next auto increment id using PHP for Joomla
  2. Sort Multi-dimensional Array
  3. Joomla PHP code to convert an array of key value pairs
  4. Get base path of Web site

Page 3 of 7

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

Main Menu

  • Home
  • Services
  • Portfolio
  • About
    • Bectin's Founder
  • Contact
  • Random Insights
    • Joomla
    • Joomla Extensions
    • Web Sites
    • Windows Computers
    • Zen Cart
    • Magento
    • MySQL
    • Business
    • Technology
    • Google Analytics & Webmaster Tools
    • PayPal
    • PHP