<?php

function simpleselect($tablename, $fieldArray, $condition, $orderArray, $orderrule, $limit)
{ 
	global $dbConnection;
		$a=1;
		$field="";
		$fieldnum=count($fieldArray);

		foreach($fieldArray as $fieldname)
		{
			$field.=$fieldname;
			if ($a<$fieldnum)
				{ 
					$field.=", ";
				}
				$a++;		
		}

		$s_query="SELECT ".$field." FROM ".$tablename;
		if ($condition!="")
		{ 
			$s_query.=" WHERE ".$condition;
		}

		//CONDITION
		if (count($orderArray)>0)		
		{ 
				$b=1;
				$ord="";
				$ordernum=count($orderArray);
				foreach($orderArray as $orderfield)
				{ 
					$ord.=$orderfield;
					if ($b<$ordernum)
						{ 
							$ord.=", ";
						}
						$b++;		
				}
				$s_query.=" ORDER BY ".$ord." ".$orderrule;
		}


		if ($limit!="")
		{
			$s_query.=" LIMIT ".$limit." ";
		}
		$s_result=mysqli_query($dbConnection, $s_query);		
		return $s_result;
}

?>