Version 0.9.5 beta - updated selectDatasetByFieldWhere with sort order and removed numeric array keys.

This commit is contained in:
Stephan Kasdorf
2020-11-06 22:19:13 +01:00
parent 790f79530e
commit 0aaa7d57ee
3 changed files with 16 additions and 6 deletions

View File

@@ -110,11 +110,12 @@ abstract class Db implements IDb
/** /**
* @param array $fieldWhere * @param array $fieldWhere
* @return mixed|void * @param false $sortOrder
* @return array|mixed
*/ */
public function selectDatasetByFieldWhere($fieldWhere = array()) public function selectDatasetByFieldWhere($fieldWhere = array(), $sortOrder = false)
{ {
return Pdo::selectDatasetByFieldAndValue(self::$table['table'], $fieldWhere); return Pdo::selectDatasetByFieldAndValue(self::$table['table'], $fieldWhere, $sortOrder);
} }
/** /**

View File

@@ -54,9 +54,17 @@ final class Pdo extends Mysql implements IPdo
return $query->fetchAll(); return $query->fetchAll();
} }
public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TABLE_NAME, $fieldAndValue = array() ) public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TABLE_NAME, $fieldAndValue = array(), $sortOrder = false )
{ {
$result = parent::getInstance( self::getSettingsSection() )->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . "';"); if(is_array($sortOrder))
{
$result = parent::getInstance( self::getSettingsSection() )->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . " ORDER BY ".$sortOrder['field']." ". $sortOrder['order'] ."';");
}
else
{
$result = parent::getInstance( self::getSettingsSection() )->getConn()->query("SELECT * FROM " . $tablename . " WHERE " . $fieldAndValue['name'] . " = '" . $fieldAndValue['value'] . "';");
}
$result = $result->fetchAll(); $result = $result->fetchAll();
$resultset = []; $resultset = [];
if(array_key_exists(0, $result)) if(array_key_exists(0, $result))

View File

@@ -66,9 +66,10 @@ interface IDb
* @desc will return a result array from the searched where field from the database * @desc will return a result array from the searched where field from the database
* containing the entire dataset rows * containing the entire dataset rows
* @param array $fieldWhere * @param array $fieldWhere
* @param false $sortOrder
* @return mixed * @return mixed
*/ */
public function selectDatasetByFieldWhere( $fieldWhere = array() ); public function selectDatasetByFieldWhere( $fieldWhere = array(), $sortOrder = false );
/** /**
* @desc selects a row by the fieldname and the given value, should be * @desc selects a row by the fieldname and the given value, should be