I need code that will after pressing submit display concerts for selected group (grupanaziv), which includes number of sold tickets for that concert, place, and date, in database they are called place=mesto, date=datum, and tickets=karte

<p align="center"><font color="#0000FF">Pregled grupa</font></p>

<p align="center">Grupa kojoj koncert pripada: 
    <select name="grupa_select" id="grupa_select">
      <?php
    while($row = mysql_fetch_array($sql))
    {
    echo "<option>".$row['grupanaziv']."</option>";
    }
    ?>
    </select>
  </p>
  <p align="center">
    <input type="submit" name="pregled_grupe" id="pregled_grupe" value="- Izaberi grupu-" />
  </p>
  <p>
    <label></label>
  </p>

Thanks in advance

So what's the problem?

Hi,

assuming you're using method GET for your form, you need to read the value assigned to $_GET['grupa_select'] and to use it as condition in your select query. So, something like:

$values = array(
    $_GET['grupa_select']
);

$sql = "SELECT * FROM concerts WHERE groupnaziv = ?";

$query = $pdo->prepare($sql);
$query->execute($values);

$result = $query->fetchAll();

foreach($result as $row)
{
    echo $row['mesto'];
    echo $row['datum'];
    echo $row['karte'];
}

Now, when you write:

in database they are called place=mesto, date=datum, and tickets=karte

Do you mean that these are the table or the column names? Please, show us the table structure.

In my example I'm using PDO, because the MySQL API is deprecated and will be removed, I suggest you to read this:

here I will post whole code, I have 3 tables, table korisnici, is for creating new users, and admin page does that, it works ok, database works fine for all stuff, now I need just code that will take data from base and display to user based on what group he selected

//Kreiranje baze podataka
$con = mysql_connect($hostname,$db_username,$db_password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

if (mysql_query("CREATE DATABASE ".$db_name,$con))
  {
  echo "Database CREATED!<br>";
  }
else
  {
  echo "Error creating database: " . mysql_error()."<br>";
  }

//Kreiranje potrebnih tabela
mysql_select_db($db_name, $con);
//Tabela korisnici
$sql = "CREATE TABLE korisnici
(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
FirstName varchar(64),
LastName varchar(64),
Username varchar(64),
Password varchar(64)
)";
mysql_query($sql,$con);
echo "Table korisnici CREATED!<br>";
//Tabela Sections
$sql = "CREATE TABLE grupe
(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
grupanaziv varchar(64)
)";
mysql_query($sql,$con);
echo "Table grupe CREATED!<br>";
//Tabela Subjects
$sql = "CREATE TABLE koncerti
(
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
koncertnaziv varchar(64),
karte int(10),
mesto varchar(64),
datum DATE,
grupa_id int(6)
)";
mysql_query($sql,$con);
echo "Table koncerti CREATED!<br>";

and here is whole php code

<?php
//Provjerava da li se korisnik vec ulogovao. Ako nije, ispisace gresku.
session_start();
if (!isset($_SESSION['korisnik'])) {
die('Za pristup ovoj stranici morate se prvo ulogovati.');
}
$student = $_SESSION['korisnik'];
  //Podaci o bazi podataka
    $hostname = "";
    $db_username = "";
    $db_password = "";
    $db_name = "";
    $con = mysql_connect($hostname,$db_username,$db_password);
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db_name, $con);
    $sql = mysql_query("select * from grupe");
    $sql_2 = mysql_query("select * from grupe");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Administracija aplikacije</title>
</head>

<body>
<p align="center"><font color="#000000"><strong>Administracija aplikacije</strong></font></p>
<form id="form1" name="form1" method="post" action="">

    <br>
  </p>
  <hr />
  <p align="center"><font color="#0000FF">Registracija grupa</font></p>
  <p align="center">Unos nove grupe: 
    <input type="text" name="grupa_new" id="grupa_new" />
  </p>
  <p align="center">Sačuvaj grupu:
    <input type="submit" name="sacuvaj_grupu" id="sacuvaj_grupu" value="- Sacuvaj grupu -" />
  </p>
  <p>&nbsp;</p>
  <p>
    <label></label>
  </p>
  </p><br>

  <?php
  if (isset($_POST['sacuvaj_grupu'])){
  $grupa_new = $_POST['grupa_new'];
  if (empty($grupa_new)){
  die ("ERROR: Niste uneli naziv grupe!");
  }
  $con = mysql_connect($hostname,$db_username,$db_password);
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db_name, $con);
    $sql = "insert into grupe values (NULL,'".$grupa_new."')";
    if (!mysql_query($sql,$con))
    {
        die('Error: ' . mysql_error());
    }
    echo "Podaci uspesno uneseni u bazu podataka!";
  }
  ?>


  <br>
  <hr />
   <p align="center"><font color="#0000FF">Registracija koncerata</font></p>
  <p align="center">Naziv koncerta: 
    <input type="text" name="enter_koncert" id="enter_koncert" />
  </p>
  <p align="center"><font color="#0000FF">Broj prodatih karata</font></p>
  <p align="center">Broj: 
    <input type="text" name="enter_karte" id="enter_karte" />
  </p>

   <p align="center"><font color="#0000FF">Mesto</font></p>
  <p align="center">Mesto: 
    <input type="text" name="enter_mesto" id="enter_mesto" />
  </p>

  <p align="center"><font color="#0000FF">Datum</font></p>
  <p align="center">Datum: 
    <input type="text" name="enter_datum" id="enter_datum" />
  </p>

  <p align="center">Grupa kojoj koncert pripada: 
    <select name="grupa_select" id="grupa_select">
      <?php
    while($row = mysql_fetch_array($sql_2))
    {
    echo "<option>".$row['grupanaziv']."</option>";
    }
    ?>
    </select>
  </p>
  <p align="center">
    <input type="submit" name="unos_koncert" id="unos_koncert" value="- Sacuvaj koncert-" />
  </p>
  <p>
    <label></label>
  </p>

 <?php
  if (isset($_POST['unos_koncert'])){
    $enter_koncert = $_POST['enter_koncert'];
    $enter_karte = $_POST['enter_karte'];
    $enter_mesto = $_POST['enter_mesto'];
    $enter_datum = $_POST['enter_datum'];
    $grupa_select = $_POST['grupa_select'];
    if (empty($enter_koncert)){
  die ("ERROR: Niste uneli naziv koncerta!");
  }
  $con = mysql_connect($hostname,$db_username,$db_password);
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db_name, $con);
        $sql = mysql_query("select id from grupe where grupanaziv ='".$grupa_select."'");
        $grupa = mysql_fetch_array($sql);
    $sql = "insert into koncerti values (NULL,'".$enter_koncert."','".$enter_karte."','".$enter_mesto."','".$enter_datum."',".$grupa['id'].")";
    if (!mysql_query($sql,$con))
    {
        die('Error: ' . mysql_error());
    }
    echo "Podaci uspesno uneseni u bazu podataka!";
  }
  ?>



  <p align="center"><font color="#0000FF">Pregled grupa</font></p>

<p align="center">Grupa kojoj koncert pripada: 
    <select name="grupa_select" id="grupa_select">
      <?php
    while($row = mysql_fetch_array($sql))
    {
    echo "<option>".$row['grupanaziv']."</option>";
    }
    ?>
    </select>
  </p>
  <p align="center">
    <input type="submit" name="pregled_grupe" id="pregled_grupe" value="- Izaberi grupu-" />
  </p>
  <p>
    <label></label>
  </p>

</form>
<p align="center"><a href="logout.php">LogOut </a></p>
</body>
</html>
<?php
mysql_close($con);
?>

I have option to add new groups, to add new concerts to specific group, to add place, date and number of sold tickets in that concert, and all that works, now I need to make available to user to see all concerts, and date,place and sold tickets for that concert, so bassicly user get option to select group(band) and after clicking submit to display all concerts and their information for that group, I started that last its called pregled grupa, need to finish it and I need help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.