<!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>Documento senza titolo</title>
<?php
$id=$_POST['classe'];
include("config.php");
include 'votiDatabase.php';
$sql=(" select * from studente where studente.classe='$id'");
$result=mysql_query($sql);
$righe=mysql_num_rows($result);
//echo "Il valore di è $id
";
?>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
funzione per prelevare la scelta della select option e metterla in un vettore
function funzione(righe) {
voto = new Array();
var cont=righe;
var sel= document.getElementsByTagName("select");
var count=sel.length;
for (var i=0; i< count; i++)
{
valore=sel[i].value;
if(valore==0)
voto[i]=3;
if(valore==1)
voto[i]=3.5;
if(valore==2)
voto[i]=4;
if(valore==3)
voto[i]=4.5;
if(valore==4)
voto[i]=5;
if(valore==5)
voto[i]=5.5;
if(valore==6)
voto[i]=6;
if(valore==7)
voto[i]=6.5;
if(valore==8)
voto[i]=7;
if(valore==9)
voto[i]=7.5;
if(valore==10)
voto[i]=8;
if(valore==11)
voto[i]=8.5;
if(valore==12)
voto[i]=9;
if(valore==13)
voto[i]=9.5;
if(valore==14)
voto[i]=10;
}
Questo è il vettore trasformato in stringa, la devo infiare ad una pagina php, come si fa??????
elementi= voto.join(',');
alert(elementi);
ho provato con $.post ma non funziona
Nella pagina php con una query inserisco i voto nel database
Il bottone nascosto serve per passare l'array contenente id_studente a cui associo il voto
$.post("votiDatabase.php", {elementi: elementi});
}
</script>
</head>
<body>
<h1> INSERIMENTO VOTI</h1>
<form name"form" action="votiDatabase.php" method="post">
<?php
for($i=0;$i<$righe;$i++)
{
$voto[$i]='-';
}
print("<table width='800' border='1'>");
print("<tr>");
print("<th scope='col'>STUDENTE</th>");
print("<th scope='col'>VOTO</th>");
print("</tr>");
$cont=3;
for($i=0;$i<$righe;$i++)
{
print("<tr>");
$fine=mysql_fetch_array($result);
print("<td>".$fine['nome']." ".$fine['cognome']."</td>");
$array[$i]=$fine['id_studente'];
print("<td>");
print("<select name='$i' id='$i'>");
print("<option value='NULL'> -");
for($j=0;$j<15;$j++)
{
print("<option value='$j'> $cont ");
$cont=$cont+0.5;
}
$cont=3;
print("</td>");
print("</tr>");
}
print("</select>");
print("</table>");
?>
<tt id="results"> </tt> </p>
<input type="hidden" name="array" value='<?php print(serialize($array));?>'/>
<input type="submit" onclick="funzione(<?php echo $righe;?>)" value="Invia" />
</form>
</body>
</html>