im a fairly newbie into javascript and php (just got less than two weeks max)however im trying to learn because i really enjoy this,anyway, right now im trying to do a proyect for the company where i work for ( not that we will use it, but as an incentive).
the proyect is about making a query in sql that would return a table, but using the parameters given in three drop down's now those three 's must pick three conditionals. ie
$sql ="SELECT * FROM catalogo WHERE escuelas='$e' and grado='$g' and seccion='$p'";
so far i have wrote ( and to be honest copy/paste a lot from different sources) the basics, but im stuck trying to a query.. anyway here is my code for the index.php
<script>
function showescuelas(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
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","ajaxdatospersonales.php?e="+str, true);
//xmlhttp.open("GET","ajaxdatospersonales.php?e="+document.getElementById("esc").value+"&gra="+document.getElementById("gra").value+"&sec="+document.getElementById("sec").value,,true);
xmlhttp.send();
}
}
</script>
</header>
<?php include_once("menu.php"); ?>
<div class="container">
<h1> Agregar apartado </h1>
<form id="form" method="post" action="procesadordatospersonales.php" >
<!-- down below is my first filter, it feeds from a table named "escuelas"-->
<p> <label for="escuelas">Escuela:</label>
<select name="escuelas" id="esc" onchange="showescuelas(this.value)">
echo "<option> </option>";
<?php
$con = mysql_connect('localhost', 'root', 'pass') or die(mysql_error());
mysql_select_db('apartados');
$sql = "SELECT escuelas FROM escuelas";
$data = mysql_query($sql,$con);
while($category = mysql_fetch_array($data)){
$catname = $category['escuelas'];
$valueid = $category['escuelas'];
echo '<option value="'.$valueid.'">'.$catname.'</option>';
}
?>
</select>
<br />
</p>
<!-- down below is my second filter, it feeds from a table named "grados"-->
<p> <label for="grado">grado:</label>
<select name="grado" id="gra" onChange="showgrados(this.value)">
echo "<option> </option>";
<?php
$con = mysql_connect('localhost', 'root', 'pass') or die(mysql_error());
mysql_select_db('apartados');
$sql = "SELECT grado FROM grado";
$data = mysql_query($sql,$con);
while($category = mysql_fetch_array($data)){
$catname = $category['grado'];
$valueid = $category['grado'];
echo '<option value="'.$valueid.'">'.$catname.'</option>';
}
?>
</select>
<br />
</p>
<!-- yep you guess it this is the last filter, it feeds from a table named "grados"-->
<p> <label for="seccion" >seccion:</label>
<select name="seccion" id="sec" onChange="showescuelas(this.value)">
echo "<option> </option>";
<?php
$con = mysql_connect('localhost', 'root', 'pass') or die(mysql_error());
mysql_select_db('apartados');
$sql = "SELECT seccion FROM seccion";
$data = mysql_query($sql,$con);
while($category = mysql_fetch_array($data)){
$catname = $category['seccion'];
$valueid = $category['seccion'];
echo '<option value="'.$valueid.'">'.$catname.'</option>';
}
?>
</select>
<br />
</p>
</div>
</div>
<div id="txtHint"><b> info will be listed here.</b></div>
<input type="submit" value="Agregar">
</form>
and this is my "ajaxdatospersonales.php"
<?php
$e=$_GET["e"];
$g=$_GET["g"];
$s=$_GET["s"];
$con = mysqli_connect('localhost','root','pass','apartados');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con);
//i made this array just to check if the variables
$test= array("$e", "$g", "$s");
echo "esta es la escuela " . $test[0] . " y este el grado " . $test[1] . " y la seccion " . $test[2] . ".";
$sql ="SELECT * FROM catalogo WHERE escuelas='$e' and grado='$g' and seccion='$p'";
$result = mysqli_query($con, $sql);
$ii=1;
echo "<table border='1'>
<tr>
<th>agregar</th>
<th>isbn</th>
<th>nombre</th>
<th>autor</th>
<th>editorial</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td> <input type='checkbox' name= isbn".$ii." value=".$row['isbn']. " </td>";
echo "<td>" . $row['isbn'] . "</td>";
echo "<td>" . $row['nombre'] . "</td>";
echo "<td>" . $row['autor'] . "</td>";
echo "<td>" . $row['editorial'] . "</td>";
echo "</tr>";
$ii++;
}
echo "</table>";
mysqli_close($con);
?>
now for some reaso it just dosent work.... i dont know whats going on.. thanks.
now if you decide to help me please, try to be as newbie frendly as possible. also i already know about sql injection. but this is a proyect for fun