The problem is that I try to pass more than one parameter in the function onchange = showService (pase, tipo, fecha) these parameters I get them by get in php and convert the variables to javascript format like this:
<? Php
$ tipo = $ _ GET ['tipo'];
$ pase = $ _ GET ['pase'];
$ fecha = $ _ GET ['fecha'];
?>
<Script>
tipo = <? Php echo $ tipo; ?>
pase = <? Php echo $ pase; ?>
fecha = <? Php echo $ fecha; ?>
</ Script>
And it does not work, it only recognizes the first parameter and if I just date it in this format (2017-02-22) when painting the received with ajax I painted "1993" and therefore the query does not do it well and I get The table empties.
And if I write directly the url getservice.php passing the variables the query does it correctly.
This is complete code
index2.php
<?php require('config.php'); ?>
<html>
<head>
<style>
.relleno {
background-color: cadetblue;
height: 200px;
width: 100%;
border: 1px solid goldenrod;
margin-bottom: 10px;
}
</style>
<script type="text/javascript">
function showService(pase,tipo,fecha)
{
if (tipo=="" && pase=="" && fecha=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open('GET','getservice2.php?pase='+pase+'&tipo='+tipo+'&fecha='+fecha,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h1>Selecciona una opción para cargar su información mediante las técnicas AJAX</h1>
<div class="relleno"></div>
<?php
$pase=$_GET[pase];
$tipo=$_GET[tipo];
$fecha=$_GET[fecha];
?>
<script type="text/javascript">
pase== <?php echo $pase; ?>
tipo== <?php echo $tipo; ?>
fecha== <?php echo $fecha; ?>
</script>
<form>
<select name="services" onChange="showService(pase,tipo,fecha)">
<option value="">Seleccione número de personas...</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<?php
/*
$query = mysql_query("SELECT service_id, title, price, date_added, date_modified, status FROM services ORDER BY title asc", $conexion);
while($row = mysql_fetch_array($query)) {
echo '<option value="'.$row['service_id'].'">'.$row['title'].'</option>';
}
*/
?>
</form>
<br />
<div id="txtHint"><b>Seleccina un servicio de la lista para ver su información.</b></div>
</body>
</html>
getservice2.php
<?php
require('config.php');
$pase = $_GET[pase];
$tipo = $_GET[tipo];
$fecha = $_GET[fecha];
$consulta="SELECT * FROM pase_completo WHERE idshow_tipo = '".$tipo."' AND idpase_tipo = '".$pase."' AND fecha = '".$fecha."'";
echo $consulta;
$query = mysql_query($consulta, $conexion);
echo "<table border='1'>
<tr>
<th>personas</th>
<th>Precio</th>
<th>Fecha de registro</th>
<th>Fecha de modificacion</th>
<th>Estado</th>
</tr>";
while($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td>" . $row['personas'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['date_added'] . "</td>";
echo "<td>" . $row['date_modified'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($conexion);
?>
Many Thanks