So the app should read from database if condition is met and print on page in this format:

here are codes and i will post image of my output in the end
lib.php:
<?php
$db_name = "ispit_septembar";
$db_user = "root";
$db_host = "localhost";
$db_pass = "";
function vratiStudente($godina)
{
global $db_name,$db_user,$db_host,$db_pass;
$studenti = array();
$link = mysql_connect("$db_host","$db_user","$db_pass") or die ("Nije moguca konekcija");
mysql_select_db("$db_name",$link) or die ("Nepostojeca baza");
$sql = mysql_query("SELECT * from studenti where godina = '$godina'");
while ($row = mysql_fetch_array($sql) )
{
$indeks = $row["indeks"];
$imeiprezime = $row["imeiprezime"];
$godina = $row["godina"];
$studenti["indeks"] = $indeks;
$studenti[$indeks]["imeiprezime"] = $imeiprezime;
$studenti[$indeks]["godina"] = $godina;
}
return $studenti;
}
function daLiPostojiStudent($indeks)
{
global $db_name,$db_user,$db_host,$db_pass;
$link = mysql_connect("$db_host","$db_user","$db_pass") or die ("Nije moguca konekcija");
mysql_select_db("$db_name","$link") or die ("Nepostojeca baza");
$sql = mysql_query("SELECT * from studenti where indeks = '$indeks'");
$check = mysql_num_rows($sql);
if ($check >0 )
{
$postoji = "postoji";
}
else
{
$postoji = "ne postoji";
}
return $postoji;
}
function dodajStudenta($indeks,$ime,$godina)
{
global $db_name,$db_user,$db_host,$db_pass;
$link = mysql_connect("$db_host","$db_user","$db_pass") or die ("Nije moguca konekcija");
mysql_select_db("$db_name","$link") or die ("Nepostojeca baza");
$result = daLiPostojiStudent($indeks);
if ($result == "postoji")
{
$postoji = "Student sa tim brojem indeksa postoji";
return $postoji;
}
else
{
$sql = ("INSERT INTO studenti (indeks,imeprezime,godina)
VALUES ('$indeks','$ime','$godina' ");
mysql_query($sql);
return 1;
}
}
?>
strana1.php:`
<?php
include "lib.php";
include "Smarty/libs/Smarty.class.php";
$dodaj1 = "strana2.php?godina=1";
$dodaj2 = "strana2.php?godina=2";
$dodaj3 = "strana2.php?godina=3";
$studenti1 = vratiStudente(1);
echo ($studenti1["indeks"]);
$studenti2 = vratiStudente(2);
$studenti3 = vratiStudente(3);
$smarty= new Smarty();
$smarty->assign("dodaj1",$dodaj1);
$smarty->assign("dodaj2",$dodaj2);
$smarty->assign("dodaj3",$dodaj3);
$smarty->assign("studenti1",$studenti1);
$smarty->assign("studenti2",$studenti2);
$smarty->assign("studenti3",$studenti3);
$smarty->display("strana1.tpl");
?>
strana1.tpl
<html>
<head>
</head>
<body>
Godina: 1 <a href ={$dodaj1}>Dodaj</a>
<hr>
<table>
<tr>
<th>Indeks</th>
<th>Ime i Prezime </th>
</tr>
{foreach name="studenti1loop" item=student key=indeks from=$studenti1}
<tr>
<td> {$indeks} </td>
<td> {$student.imeiprezime}</td>
<td>{$student.godina}</td>
</tr>
{/foreach}
</table>
{* druga godina*}
Godina: 2 <a href ={$dodaj2}>Dodaj</a>
<hr>
<table>
<tr>
<th>Indeks</th>
<th>Ime i Prezime </th>
</tr>
{foreach name="studenti2loop" item=student from =$studenti2}
<tr>
<td> {$indeks} </td>
<td> {$student.imeiprezime}</td>
<td>{$student.godina}</td>
</tr>
{/foreach}
</table>
{* treca godina*}
Godina: 3 <a href ={$dodaj3}>Dodaj</a>
<hr>
<table>
<tr>
<th>Indeks</th>
<th>Ime i Prezime </th>
</tr>
{foreach name="studenti2loop" item=student from=$studenti3}
<tr>
<td> {$indeks} </td>
<td> {$student.imeiprezime}</td>
<td>{$student.godina}</td>
</tr>
{/foreach}
</table>
</body>
this is my_sql base structure:

and my output (Wrong one):

and now, questions:
I can’t figure out why first member of frist array ($studenty1) as attributes index,imeiprezime and godina has indeks,3,3 – it should be 12345,dusan skoric, 1.
And second question, why is last indeks attribute from last member of first array used as ideks attribute for every member of next two arrays(Studenti2,studenti3)
ok, i’ve solved my first question:
line studenti[“indeks”] = $indeks in lib.php was making problems, but still cant find answer to second question