Ciao a tutti!
Allora avrei un piccolo problema...
Ho realizzato queste due pagine che vi posterò sotto che in pratica producono una select e in base all'elemnto scelto dalla select interrogono il database e stampano determinate cose...
Il problema è che io vorrei aggiungere al carrello l'elemento della tabella dinamica scelto dall'utente.
Aggiungi al carrello l'ho messo, ho pure cambiato e non metto create textnode ma setAttribute, ma non me lo fa vedere come collegamento...
dove è sbagliato???
Grazie mille!
provasito3.php
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Post</title>
</head>
<body>
<div id="xmldata"></div>
<script type="text/javascript">
function readyAJAX() {
try {
return new XMLHttpRequest();
} catch(e) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
return "Hai bisogno di un altro browser.";
}
}
}
}
function mostraInfo(data)
{
var requestObj = readyAJAX();
var url = "mostra_utenti_prova3.php";
var params = "q=" + data;
requestObj.open("POST",url,true);
requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
requestObj.send(params);
requestObj.onreadystatechange = function() {
if (requestObj.readyState == 4) {
if (requestObj.status == 200) {
var serverResponse = requestObj.responseXML;
var header = serverResponse.getElementsByTagName("user");
htmlString = "<table><tr><th>Fila</th><th>Posto</th></tr>";
for (i=0; i<header.length; i++)
{
htmlString += "<tr>";
if (window.ActiveXObject)
{
htmlString += "<td>" + header[i].childNodes[0].text + "</td>";
htmlString += "<td>" + header[i].childNodes[1].text + "</td>";
htmlString += "<td>" + header[i].childNodes[2].text + "</td>";
}
else
{
htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
htmlString += "<td>" + header[i].childNodes[2].textContent + "</td>";
}
htmlString += "</tr>";
}
htmlString += "</table>";
document.getElementById('info').innerHTML = htmlString;
} else {
alert(requestObj.statusText);
}
}
}
}
</script>
<form>
<form>
Seleziona fila:
<select name="users" onChange="mostraInfo(this.value)">
<?php
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
//Seleziono quelli che sono i dipendenti
$connessione = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $connessione);
$query = "SELECT distinct fila
FROM teatro
WHERE disp='true' AND tempo='true'
ORDER BY fila ";
$result = mysql_query($query);
while($riga = mysql_fetch_array($result)){
echo "<option value='$riga[fila]'>$riga[fila] </option>";
}
?>
</select>
</form>
<div id="info"></div>
</body>
</html>
mostra_utenti_prova3.php
Codice PHP:
<?php
header('Content-Type: text/xml');
$db_host = "localhost";
$db_user = "administrator";
$db_password = "administrator";
$db_database = "ticket";
$con = mysql_connect($db_host,$db_user,$db_password);
mysql_select_db($db_database, $con);
$q=$_POST['q'];
$sql="SELECT *
FROM teatro
WHERE fila = '".$q."' ";
$result = mysql_query($sql);
$xml = new DomDocument('1.0');
$info = $xml->createElement('informations');
$info = $xml->appendChild($info);
while ($row = mysql_fetch_array($result))
{
$user = $xml-> createElement('user');
$user = $info->appendChild($user);
$fila = $xml->createElement('fila');
$fila = $user->appendChild($fila);
$value = $xml->createTextNode($row['fila']);
$value = $fila->appendChild($value);
$posto = $xml->createElement('posto');
$posto = $user->appendChild($posto);
$value = $xml->createTextNode($row['posto']);
$value = $posto->appendChild($value);
$a = $xml->createElement('a','Aggiungi al carrello');
$a = $user->appendChild($a);
$value = $a->setAttribute('href', 'ecomm_view_product.php');
$value = $a->appendChild($value);
}
$output = $xml->saveXML();
echo $output;
?>