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

Finding Next auto increment id using PHP for Joomla

Code to get the next value of autoincrement for a table being used by joomla

 

            $query = "SELECT `AUTO_INCREMENT` FROM  INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{$databaseName}' AND TABLE_NAME = CONCAT('{$prefix}','stride_data')";
            $db->setQuery($query);
            $db->query();
            $NextId = $db->loadAssocList();
            //echo $NextId[0][AUTO_INCREMENT];

Sort Multi-dimensional Array

This code takes an array from model and sorts it on two dimensions of the array.

$new_array = array();
foreach($this->items as $temp)
{
    $new_array[] = array("id"=>$temp->id, "CoachName" => $temp->CoachName, "CoachEmail" => $temp->CoachEmail, "SkaterName"=>$temp->SkaterName, "SkaterScno"=>$temp->SkaterScno, "Test"=>$temp->Test, "Dance"=>$temp->Dance, "SheetName"=>$temp->SheetName, "Partner"=>$temp->Partner, "GoldChallenge"=>$temp->GoldChallenge, "ClubNumber"=>$temp->ClubNumber);
}
foreach($new_array as $key => $row)
{
    $SheetName[$key] = $row['SheetName'];
    $SkaterName[$key] = $row['SkaterName'];
}
array_multisort($SheetName, SORT_ASC, $new_array, $SkaterName, SORT_ASC, $new_array);

Joomla PHP code to convert an array of key value pairs

$sql = "SELECT `parameter`, `value` FROM `#__testday_configuration` ";
    $db->setQuery($sql);
    $db->query();
    $results = $db->loadAssocList();
    $config = array();
    foreach($results as $result)
    {
        $config[$result[parameter]] = $result[value];
    }

Now you can use $config['address'] to access the value assigned to address.

Get base path of Web site

I wanted to use a a PHP include or require in a field in an RSForms Pro form. To do this properly, I needed the base URL of the site. Here's what worked to get the base URL and the rest of the include.

//<code>
require(preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']) . '/includes/testday.php');
$items=get_session_list();
return($items);
//</code>

 

 

Get the article ID of an article in a blog view

In this case, I needed to find the id of an article that was in a blog view. To do this in blog.php, you'll find that there is already the following code:

            $this->item = &$item;

which contains an array of all the article parameters and content. As a result if you put:

            echo $this->item->id;

immediately after it, you get the id number of the article.

  1. PHP code for use in a Joomla template to set the background image to be the full_text image from the article or the image for the category
  2. Using the Full Text image as a Background image
  3. To retrieve the URL of the intro image in a Joomla article
  4. Problem with accented characters not showing up using PHP and MySQL

Page 4 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