Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:00:22+00:00 2026-06-04T18:00:22+00:00

So the app should read from database if condition is met and print on

  • 0

So the app should read from database if condition is met and print on page in this format:
enter image description here
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:
enter image description here

and my output (Wrong one):
enter image description here

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)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:00:24+00:00Added an answer on June 4, 2026 at 6:00 pm

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing application for android by using flex. That app should read sms from
EDIT2 Looks like I can't read properly, disregard this post, I will try to
I have some data (Student info), and my app should be able to read
What should I read for creating a basic augmented reality app for android? I
The main menu of my app should look like this : http://imageshack.us/photo/my-images/31/accueilpart1.jpg/ and after
My iPhone app will have read-only system data AND read/write user data (stored either
How should a Windows 8 Metro application connect to a central database? I've read
I'm failing a bit to get this working. I read out a date from
My company has this Huge Database that gets fed with (many) events from multiple
I have database in the MyApp.app/Contents/Resources folder. I want at least to read data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.