<?php
$server = "localhost";
$username= "pcpomoc_potni";
$password="boroko";
$database="pcpomoc_potni";

function getNalog($id){
	global $server, $username, $password, $database;
	$con = mysql_connect($server,$username,$password);
	if (!$con){
		echo('Could not connect: ' . mysql_error());
	}
	mysql_select_db($database, $con);
	mysql_query("SET NAMES 'utf8'") or die(mysql_error());
	mysql_query("SET lc_time_names = 'sl_SI'") or die(mysql_error());
	$result=mysql_query("SELECT * FROM nalog WHERE id='$id'");
	$row=mysql_fetch_array($result);
	return $row;
	mysql_close($con);
}
function getNalogBySerija($serija){
	global $server, $username, $password, $database;
	$con = mysql_connect($server,$username,$password);
	if (!$con){
		echo('Could not connect: ' . mysql_error());
	}
	mysql_select_db($database, $con);
	mysql_query("SET NAMES 'utf8'") or die(mysql_error());
	mysql_query("SET lc_time_names = 'sl_SI'") or die(mysql_error());
	$result=mysql_query("SELECT * FROM nalog WHERE serija='$serija'");
	$results=array();
    while ( $results[] = mysql_fetch_object ( $result ) );
    array_pop ( $results );
	return $results;
	mysql_close($con);
}
function getTBLNalog($serija){
	global $server, $username, $password, $database;
	$con = mysql_connect($server,$username,$password);
	if (!$con){
		echo('Could not connect: ' . mysql_error());
	}
	mysql_select_db($database, $con);
	mysql_query("SET NAMES 'utf8'") or die(mysql_error());
	mysql_query("SET lc_time_names = 'sl_SI'") or die(mysql_error());
	$result=mysql_query("SELECT * FROM tbl_nalog WHERE serija='$serija'");
	$row=mysql_fetch_array($result);
	return $row;
	mysql_close($con);
}
function getAvto($id){
	global $server, $username, $password, $database;
	$con = mysql_connect($server,$username,$password);
	if (!$con){
		echo('Could not connect: ' . mysql_error());
	}
	mysql_select_db($database, $con);
	mysql_query("SET NAMES 'utf8'") or die(mysql_error());
	mysql_query("SET lc_time_names = 'sl_SI'") or die(mysql_error());
	$result=mysql_query("SELECT * FROM tbl_avto WHERE id='$id'");
	$row=mysql_fetch_array($result);
	return $row;
	mysql_close($con);
}

function setTBLNalog($serija){
	global $server, $username, $password, $database;
	$con = mysql_connect($server,$username,$password);
	if (!$con){
		echo('Could not connect: ' . mysql_error());
	}
	mysql_select_db($database, $con);
	mysql_query("SET NAMES 'utf8'") or die(mysql_error());
	mysql_query("SET lc_time_names = 'sl_SI'") or die(mysql_error());
	$result=mysql_query("SELECT * FROM nalog WHERE serija='$serija'");
	
	$vsota=0;
	$km=0;
	while($row=mysql_fetch_array($result)){
		$vsota+=$row['cena'];
		$km+=$row['km'];
	}
	
	mysql_query("UPDATE tbl_nalog SET skupna_cena='$vsota' WHERE serija='$serija'");
	mysql_query("UPDATE tbl_nalog SET skupaj_km='$km' WHERE serija='$serija'");
		
	mysql_close($con);
}

?>