simpleAdminPlus v1.0

simpleAdminPlus Query

Click on a function to expand it.

sql() $simpleAdmin->query->sql()
sql() – Runs a regular sql query and returns the sql resource.

Usage

$simpleAdmin->query->sql( [sql_query] )
sql_query string (required)
This should be standard sql code.
(e.g SELECT * FROM `products` WHERE `category_id` = '2')

Example

<?php
if( $result = $simpleAdmin->query->sql("SELECT * FROM `products` WHERE `category_id` = '2'") ) {
	
	if( mysql_num_rows($result) > 0 ) {
		
		while( $row = mysql_fetch_object($result) ) {
			echo 'Title: ' . $row->title;
		}
	}else { // If no rows were found
		echo 'No rows to display';
	}
		
}
?>
get_results() $simpleAdmin->query->get_results()
get_results() – Runs a regular sql query and returns all the rows in an object.
This method is better than get_rows because you have more control, but it is does not initialize the paging_links.

Usage

$simpleAdmin->query->get_results( [sql_query] )
sql_query string (required)
This should be standard sql code.
(e.g SELECT * FROM `products` WHERE `category_id` = '2')

Example

<?php
$products = $simpleAdmin->query->get_results("SELECT * FROM `products` WHERE `category_id` = '2'");
foreach( $products as $product ) :
	echo $product->title;
endforeach;
?>
insert() $simpleAdmin->query->insert()
insert() – Inserts data into a table.

Usage

$simpleAdmin->query->insert( [table_name], [data], [value] )
table_name string (required)
Chooses the table to insert data into.
data string or array (required)

If you are inserting into multiple columns, then you should use an array, but if your only inserting into one column then you can supply the column name.

value string (default=null)

If you are inserting into one column, this is where you supply the column value.

Example (Multiple Columns)

<?php
$simpleAdmin->query->insert('products', array(
	'title'       => mysql_real_escape_string($title),
	'description' => mysql_real_escape_string($description),
	'category_id' => mysql_real_escape_string($category_id)
));

echo "Product Added Successfully";
?>

Example (Single Column)

<?php
$simpleAdmin->query->insert('products', 'title', 'Added with simpleAdminPlus');
echo 'Added Successfully!';
?>
update() $simpleAdmin->query->update()
update() – Updates data in a table.

Usage

$simpleAdmin->query->update( [table_name], [data], [where], [where_column] )
table_name string (required)
Chooses the table to insert data into.
data array (required)
The data to update in the table
where int or string (required)
The where value to insert the data.
WHERE `id` = '[where]'
where_column string (default=id)
This is the column to set which row to update.
WHERE `[where_column]` = '13'

Example

<?php
$simpleAdmin->query->update('products', array(
	'title'       => mysql_real_escape_string($title),
	'description' => mysql_real_escape_string($description),
	'category_id' => mysql_real_escape_string($category_id)
), 3, 'prod_id');
?>