Forum Moderators: coopster
<?
echo "<form name=sel>\n";
echo "Type : <font id=type><select>\n";
echo "<option value=''>============</option> \n" ;
echo "</select></font>\n";
echo "Quality : <font id=quality><select>\n";
echo "<option value=''>=== none ===</option> \n" ;
echo "</select></font>\n";
echo "Count : <font id=count><select>\n";
echo "<option value=''>=== none ===</option> \n" ;
echo "</select></font>\n";
?>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText; //retuen value
}
}
};
req.open("GET", "state.php?data="+src+"&val="+val); //make connection
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
req.send(null); //send value
}
window.onLoad=dochange('type', -1); // value in first dropdown
</script>
<?
$data=$_GET['data'];
$val=$_GET['val'];
$vType = " ";
$vQuality = " ";
//set database
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// first dropdown
switch($data){
case 'type':
echo "<select name='type' onChange=\"dochange('quality', this.value)\">\n";
echo "<option value=''>==== choose type ====</option>\n";
$result=mysql_db_query($database,"SELECT DISTINCT type FROM prod");
while(list($type)=mysql_fetch_array($result)){
echo "<option value=\"$type\" >$type</option> \n" ;
}
break;
// second dropdown
case 'quality':
echo "<select name='quality' onChange=\"dochange('count', this.value)\" >\n";
echo "<option value=''>====choose quality ====</option>\n";
$vType= $val;
$result=mysql_db_query($database,"SELECT DISTINCT quality FROM prod WHERE type='".$vType."'");
while(list($quality)=mysql_fetch_array($result)){
echo "<option value=\"$quality\" >$quality</option> \n" ;
}
break;
// third dropdown
case 'count':
echo "<select name='count' >\n";
echo "<option value=''>====choose count ====</option>\n";
$vQuality = $val;
$result=mysql_db_query($database,"SELECT DISTINCT count FROM prod WHERE type = '".$vType."' AND quality = '".$vQuality."'");
while(list($count)=mysql_fetch_array($result)){
echo "<option value=\"$count\" >$count</option> \n" ;
}
break;
}
echo "</select>\n";
?>
switch($data)
{
case "type":
//code here
break;
case "quality":
//code here
break;
case "count":
//code here
break;
}
function some_func()
{
//call var set from parent file
global $someVar;
//php will then search for a var with the name $someVar within the script, even checking files referenced in any include paths
}
mysql_connect(localhost,$username,$password);
mysql_connect("localhost",$username,$password);
$result=mysql_db_query($database,"SELECT DISTINCT type FROM prod")or die(mysql_error());
$result=mysql_db_query($database,"SELECT DISTINCT type FROM prod");
if($result){
while(list($type)=mysql_fetch_array($result)){
echo "<option value=\"$type\" >$type</option> \n" ;
}
}else{
echo "No results returned!";
exit;
}
$conn = mysql_connect("host", "username","pass") or die(mysql_error());
mysql_select_db("db_name", $conn) or die(mysql_error());
<?php
//Session start
session_start();
//Set error reporting for dev use...
error_reporting(E_ALL);
....then the rest of your code
<html>
<head>
<title>My PHP script
</title>
</head>
<body>
<?php
session_start();
//this wont work as headers have been sent
?>
<p>My content</p>
<?php
//start session
session_start();
//Error reporting
error_reporting(E_ALL);
//this will as php is the first thing on the document
?>
<html>
<head>
<title>My PHP script
</title>
</head>
<body>
<p>My content</p>
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Inetpub\vhosts\accofinance.com\httpdocs\testfinal\state.php:3) in C:\Inetpub\vhosts\accofinance.com\httpdocs\testfinal\state.php on line 4