I am a bit new (not a novice but also not a big expert) in PHP5 and MySQL.
First of all if there is a similar thread or topic I am sorry for that topic. Unfortunately, I don't have much time to explore through the foren.
What I did is first of all I have created a DB named fernschule
It has three tables:
t_kurse (Courses)
t_institute(Institutes)
t_ins_kurse (for 1 .. * relationship)
t_kurse has these fields:
KURSE_NAME
KURSE_CODE (primary key)
t_institute has these fields:
INS_NAME
INS_CODE (primary key)
t_ins_kurse has two foreign keys which are
INS_CODE
KURSE_CODE
what I am trying to do is to get the all course names sorted by ascending into a combobox and to search if which institutes have these courses.
So my first php file (trial.php) is this
Code: Select all
<?php
/*
* Created on 12.11.2006
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
$link = mysql_connect('localhost','root','admin');
$db = mysql_select_db("fernschule");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$sqlquery = "select * from t_kurse ORDER BY KURSE_NAME";
$res = mysql_query($sqlquery);
echo "<FORM ACTION = 'trial1.php' METHOD = 'POST'>";
echo "<SELECT NAME ='t_kurse'>";
while($dsatz = mysql_fetch_assoc($res)) {
$value = $dsatz["KURSE_CODE"];
echo "<OPTION VALUE=".$value."SELECTED>".$dsatz["KURSE_NAME"]."</OPTION>";
}
echo "<INPUT TYPE = 'SUBMIT' VALUE = 'Suchen'>";
echo "<input type='reset' VALUE = 'Abbrechen'>";
mysql_close($link);
?>Code: Select all
<?php
/*
* Created on 11.12.2006
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
include 'trial.php';
$link = mysql_connect('localhost','root','admin');
$db = mysql_select_db("fernschule");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$sqlquery = "SELECT t_institute.INS_NAME
FROM t_kurse INNER JOIN (t_institute INNER JOIN t_ins_kurse ON t_institute.INS_CODE=t_ins_kurse.INS_CODE) ON t_kurse.KURSE_CODE=t_ins_kurse.KURSE_CODE
WHERE(((t_kurse.KURSE_CODE)=" .$_POST['value']."))";
$res = mysql_query($sqlquery);
while($dsatz = mysql_fetch_assoc($res)) {
echo "<p>".$dsatz["INS_NAME"]."</P>";
}
?>