Hi i currently use javascript to call small function that run a sql query on a secondary page i have about 4 to 5 of these small scripts and i was just wondering how to put them all together and be able to call the one i need out of this one page instead of having 5 different scripts that have 3 to 5 lines of code in. my code and process is below.
first the JavaScript that I am Currently using.
$("select#principle").attr("disabled","disabled");
$("select#type").change(function(){
var id = $("select#type option:selected").attr('value');
$("select#principle").attr("disabled","disabled");
$("select#principle").html("<option>wait...</option>");
$.post("select_principle.php", {id:id}, function(data){
$("#Options").addClass("active");
$("select#principle").removeAttr("disabled");
$("select#principle").html(data);
});
});
This is a JavaScript function that I use it checks to see if a drop down box has been selected and then removes the disable attribute for the next one. but as you see there is a $.Post
this calls a PHP page.
the page that is called is
<?php
include "select.class.php";
echo $opt->ShowPrinciple();
?>
this is the php code that goes to the select.class.php page and runs a sql query. this is also the code that i have multiple of i want this to be in one script with others that call other functions the same way but they have to be run only when they are called.
the SQl query that is run is below
// this displays the principle when called
public function ShowAllPrinciple()
{
$sql = "SELECT principle.principle_id,principle.description,principle.section_id,COUNT(media.principle_id) as media_count
FROM principle
LEFT OUTER JOIN media ON principle.principle_id = media.principle_id
AND principle.section_id = media.section_id
WHERE principle.section_id={$_POST['id']}
GROUP BY principle.principle_id,principle.description";
$res = mysql_query($sql,$this->conn);
$principle = '<option value="%">choose...</option>';
while($row = mysql_fetch_array($res))
{
$principle .= '<option value="' . $row['principle_id'] . '">' . $row['description']. '...('.$row['media_count'].') </option>';
}
return $principle;
}
this is just a simple SQL query that connects to the database and then gets the data and displays it into the drop down box.
any ideas on how I can put these small scripts into one page and call the specific function using JavaScript only small scripts need to be within a PHP page and the SQL query is within a PHP page this cannot change.
<?php
include "select.class.php";
echo $opt->ShowPrinciple();
?>
any help would be much appreciated