0

i have tree select boxes. i fill those with data coming from a database (mysql)
i want to change the data of the last two selects regarding the selection of the first.
here is my code. it doesnt work (i used a little bit of javascript)

in head

<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='apousies.php?cat=' + val ;
}</script>

in body

//connect with database works fine
@$cat=$_GET['cat']; 
@$cat=$HTTP_GET_VARS['cat']; 

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT eidikotita, id_eidikotitas FROM eidikotita order by eidikotita"); 
///////////// End of query for first list box////////////


if(isset($cat) and strlen($cat) > 0){
//it never gets here
$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members where id_eid=$cat order by lastname"); 
$quer1=mysql_query("SELECT mathima FROM mathimata where id_eid=$cat order by mathima");
}else{$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members order by lastname");
$quer1=mysql_query("SELECT mathima FROM mathimata order by mathima"); } 


echo "<form method=post name=f1 action='apousies-ins.php'>";

//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>lessons</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['id_eidikotitas']==@$cat){echo "<option selected value='$noticia2[id_eidikotitas]'>$noticia2[eidikotita]</option>"."<BR>";}
else{echo  "<option value='$noticia2[id_eidikotitas]'>$noticia2[eidikotita]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Êáôáñôéæüìåíïò</option>";
while($noticia = mysql_fetch_array($quer)) { 
echo  "<option value='$noticia[lastname], $noticia[firstname], $noticia[fathersname]'>$noticia[lastname], $noticia[firstname], $noticia[fathersname] </option>";
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////

////third list

echo "<select name='subcat1'><option value=''>ÌÜèçìá</option>";
while($noticia = mysql_fetch_array($quer1)) { 
echo  "<option value='$noticia[mathima]'>$noticia[mathima] </option>";
}
echo "</select>";
//////////////////  This will end the third drop down list ///////////

echo "</form>";

the $cat variable seems empty.

i know i may ask a lot. if it is not possible to check this code could u advice me on how can i solve this problem? (the content of one select box is geting data regarding the selection of a first select box)

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

2
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by CFROG
0

If $cat seems to be empty on that page, go back the page where you originally defined $cat. Since you are passing the variable from another page it would seem to me that you are merely passing an empty variable. What does the code look like where you originally define $cat?

0

Sorry, wasn't paying attention and just realized that $cat was coming from the same page. This snippet looks a little suspicious to me ... <option value=''>lessons</option> .

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

0

it does not work even if i put this line out.

when i pick something from first select box the form reloads. in the adress line shows my pick (ex. http//:......./bathmoi.php?cat=11, but the select box does not keep my selection and the second and third select boxes does not contain the data they should regarding my pick

the variable cat is still empty. thats why. should it be empty? someone please....

0

I wouldn't omit that line, it may be correct I just never seen it done that way. I would typically use <option value="lessons">lessons</option> or simply <option>lessons</option> if you don't need to assign a value. Have you tried to echo $cat to be sure it is empty? What I would do to make sure a selection reappears upon submitting the form would be something like <option selected="selected"><?=$cat?></option> <option>lessons</option> . That would ensure your select box holds your selection given $cat is not empty, and it does not appear to me that it would be.

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

0

Does this just "reload" the form, or does it actually submit it? <select name='cat' onchange=\"reload(this.form)\"> If it is simply reloading it $cat will not contain a value.

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

0

of course i echoed the variable. it is empty for sure!

it never gets in here

if(isset($cat) and strlen($cat) > 0){
//never in here!!!!!
$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members where id_eid=$cat order by lastname"); 
$quer1=mysql_query("SELECT mathima FROM mathimata where id_eid=$cat order by mathima");
}else{$quer=mysql_query("SELECT lastname, firstname, fathersname FROM members order by lastname");
$quer1=mysql_query("SELECT mathima FROM mathimata order by mathima"); }

i think u r right about the reload issue. it probably just reloads the form without submiting it. i did not know how could i submit the form by just picking somenthing from a select box. (it would be easy for me if i could place a submit button) how could i do that?

A! an issue is that right now when i pick something from the first select box - the form reloads, and in the adress line the $cat has value!!!
adress line after a random pick:
http://iek-kozan.koz.sch.gr/admin/bathmoi/bathmoi.php?cat=14

remenber the reload function

<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='bathmoi.php?cat=' + val ;
}</script>

but my echoes still remains empty. i am confused. what shoul i do???

Edited by dourvas: n/a

0

If I'm understanding correctly and you want to use a submit button, that is easy. For the code you are working with it would look something like

echo '<input type="submit" name="button_name" id="button_id" value="Submit" />'; 
echo '</form>';

As far $cat showing up in the URL, I would think that $_GET['cat']; should do what you want. I've used '@' to suppress errors before, but I never seen it used in front of a variable. Is there are a reason you are doing it that way?

0

One other thing you may want to adjust is that you are using POST as your form method, and using GET to set your variable. One or the other should be changed so they are the same.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.