Cao svima.
Ovako sam nesto pokusao:
Kod koji smi mi dao. On mi pravi combo box koji izvlaci imena skola.
<?php
// Connect to the database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("skolski_dnevnik") or die(mysql_error());
// Has the form been submitted?
if (isset($_POST['id_skole'])) {
// The form has been submitted, query results
$queryitem = "SELECT * FROM skola WHERE id_skole = '".$_POST['id_skole']."';";
// Successful query?
if($result = mysql_query($queryitem)) {
// More than 0 results returned?
if($success = mysql_num_rows($result) > 0) {
// For each result returned, display it
while ($row = mysql_fetch_array($result)) echo $row[ime_ucenika];
}
// Otherwise, no results, tell user
else { echo "No results found."; }
}
// Error connecting? Tell user
else { echo "Failed to connect to database."; }
}
// The form has NOT been submitted, so show the form instead of results
else {
// Create the form, post to the same file
echo "<form method='post' action='example.php'>";
// Form a query to populate the combo-box
$queryitem = "SELECT DISTINCT * FROM ucenici;";
// Successful query?
if($result = mysql_query($queryitem)) {
// If there are results returned, prepare combo-box
if($success = mysql_num_rows($result) > 0) {
// Start combo-box
echo "<select name='item'>n";
echo "<option>-- Select Item --</option>n";
// For each item in the results...
while ($row = mysql_fetch_array($result))
// Add a new option to the combo-box
echo "<option value='$row[id_skole]'>$row[ime_ucenika]</option>n";
// End the combo-box
echo "</select>n";
}
// No results found in the database
else { echo "No results found."; }
}
// Error in the database
else { echo "Failed to connect to database."; }
// Add a submit button to the form
echo "<input type='submit' value='Submit' /></form>";
}
?>
Kada kliknem na zeljenu skolu, potrebno mi je da izbaci sve ucenike iz te skole. To sam pokusao ovako.
<?php
$r = mysql_query("SELECT * FROM ucenik WHERE id_skole={$_REQUEST['id_skole']}");
$vest=mysql_fetch_array($r);
echo '<h1>', $vest['ocena'], '</h1>';
echo '<p>', $vest['id_ucenika'], '</p>';
?>
GRESKE:
Notice: Undefined index: id_skole in C:\wamp\www\Testiranje\New folder\example.php on line 9
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\Testiranje\New folder\example.php on line 10
__________________________________________________
Nadam se da sam delimicno u pravu, ali mi ne radi i dalje. Pokusavam da uhvatim pomocu $_REQUEST[id_skole] id_skole iz prvog dela, i da ga povucem u upit koji bi mi iylistao podatke.
Ima li pomoci?
|