Alpricc Posted June 10, 2012 at 05:11 PM Report Share #461797 Posted June 10, 2012 at 05:11 PM (edited) Boa tarde. Eu queria saber se existe alguma forma para passar variaveis por url atraves de dados de uma combobox. O codigo que tenho é o seguinte: <?php $h=$_POST['hora']; $ds=$_POST['dsemana']; $t=$_POST['turma']; $l=$_GET['h'.'ds']; if(isset($_POST['submit'])) { echo'<form name="get" action="teste.php?" method="POST"> <select name="hora" onChange="get.submit();"> <option value="'.$h.'">'.$h.'</option> <option value="8:20">8:20/9:05</option> <option value="9:05">9:05/9:50</option> <option value="10:05">10:05/10:50</option> <option value="10:50">10:50/11:35</option> <option value="11:45">11:45/12:30</option> <option value="12:30">12:30/13:15</option> <option value="13:30">13:30/14:15</option> <option value="14:15">14:15/15:00</option> <option value="15:15">15:15/16:00</option> <option value="16:00">16:00/16:45</option> <option value="16:55">16:55/17:40</option> <option value="17:40">17:40/18:25</option> </select> <select name="dsemana" onChange="get.submit();"> <option value="'.$ds.'">'.$ds.'</option> <option value="segunda-feira">Segunda-Feira</option> <option value="terca-feira">Terça-Feira</option> <option value="quarta-feira">Quarta-Feira</option> <option value="quinta-feira">Quinta-Feira</option> <option value="sexta-feira">Sexta-Feira</option> </select> </form>';} else { echo'<form name="get" action="teste.php?" method="POST"> <select name="hora" onChange="get.submit();"> <option value="'.$h.'">'.$h.'</option> <option value="8:20">8:20/9:05</option> <option value="9:05">9:05/9:50</option> <option value="10:05">10:05/10:50</option> <option value="10:50">10:50/11:35</option> <option value="11:45">11:45/12:30</option> <option value="12:30">12:30/13:15</option> <option value="13:30">13:30/14:15</option> <option value="14:15">14:15/15:00</option> <option value="15:15">15:15/16:00</option> <option value="16:00">16:00/16:45</option> <option value="16:55">16:55/17:40</option> <option value="17:40">17:40/18:25</option> </select> <select name="dsemana" onChange="get.submit();"> <option value="'.$ds.'">'.$ds.'</option> <option value="segunda-feira">Segunda-Feira</option> <option value="terca-feira">Terça-Feira</option> <option value="quarta-feira">Quarta-Feira</option> <option value="quinta-feira">Quinta-Feira</option> <option value="sexta-feira">Sexta-Feira</option> </select> </form>';} ?> Aguardo resposta Obrigado Edited June 11, 2012 at 08:29 AM by brunoais geshi! Link to comment Share on other sites More sharing options...
KTachyon Posted June 10, 2012 at 05:28 PM Report Share #461802 Posted June 10, 2012 at 05:28 PM Coloca o código dentro das tags apropriadas para facilitar a leitura. Basicamente, tu tens um form que está a passar as variáveis por POST para o teste.php. Se queres que essas variáveis apareçam no URL, utilizas GET. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 10, 2012 at 05:30 PM Report Share #461803 Posted June 10, 2012 at 05:30 PM é difícil perceber realmente o que pretendes ... mas acho que será isto: <form name="get" action="teste.php?" method="POST"> passa para <form name="get" action="teste.php?" method="GET"> IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 10, 2012 at 06:02 PM Author Report Share #461806 Posted June 10, 2012 at 06:02 PM é difícil perceber realmente o que pretendes ... mas acho que será isto: <form name="get" action="teste.php?" method="POST"> passa para <form name="get" action="teste.php?" method="GET"> Eu vou tentar explicar o que queria. Eu quero que o utilizador escola uma hora e um dia da semana e esse valor vá para a url para depois pegar nele e fazer uma consulta na base de dados para obter outros dados para outra combobox! é difícil perceber realmente o que pretendes ... mas acho que será isto: <form name="get" action="teste.php?" method="POST"> passa para <form name="get" action="teste.php?" method="GET"> Ja mudei para GET e ja obtenho o valor das combo box no url, mas como faço agora para coloca-las numa variavel? Para depois usar esses valores num comando SQL! Link to comment Share on other sites More sharing options...
KTachyon Posted June 10, 2012 at 06:03 PM Report Share #461809 Posted June 10, 2012 at 06:03 PM E é isso que faz. No teu ficheiro teste.php recebes a informação e tratas de realizar a query à base de dados. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
Alpricc Posted June 10, 2012 at 06:08 PM Author Report Share #461810 Posted June 10, 2012 at 06:08 PM mas que variavel uso no comando sql ? Select * FROM horario WHERE hora=RESULTADO DA COMBOBOX HORA AND diasemana=RESULTADO DA COMBOBOX DIASEMANA Como preencho a parte do WHERE? Link to comment Share on other sites More sharing options...
KTachyon Posted June 10, 2012 at 07:28 PM Report Share #461815 Posted June 10, 2012 at 07:28 PM (edited) Em MySQL, podes fazer pesquisas por horas e datas com strings. Mas penso que o formato é o hh:mm:ss. Tu recebes os parâmetros, tal como fizeste no teu código inicial, e colocas os valores na query. Edited June 10, 2012 at 07:29 PM by KTachyon “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
Alpricc Posted June 10, 2012 at 08:58 PM Author Report Share #461829 Posted June 10, 2012 at 08:58 PM Eu fiz esta parta do codigo, mas neste momento a ultima combobox não está a ir buscar os meus dados à base de dados. Alguem me pode explicar o porque? :c <?php session_start(); $liga=mysql_connect('localhost','root','') or die('Problemas na ligaÁ„o ao MYSQL'); if ($_SESSION['cod'] <> '') { mysql_select_db('sistemadefaltas',$liga); $turmas = 'SELECT Turma FROM turmacurso'; $tresultado=mysql_query($turmas,$liga); $disciplinas='SELECT CodDisci FROM horario WHERE Turma=\''.$t.'\''; $dresultado=mysql_query($disciplinas,$liga); $h=$_GET['hora']; $ds=$_GET['dsemana']; $t=$_GET['turma']; $d=$_GET['disciplinas']; $l=$h.$ds.$t.$d; echo $l.'<br />'; echo $h.'<br />'; echo $ds.'<br />'; echo $t.'<br />'; echo $d.'<br />'; echo'<form name="get" action="teste.php?" method="GET"> <select name="hora" onChange="get.submit();"> <option value="'.$h.'">'.$h.'</option> <option value="8:20">8:20/9:05</option> <option value="9:05">9:05/9:50</option> <option value="10:05">10:05/10:50</option> <option value="10:50">10:50/11:35</option> <option value="11:45">11:45/12:30</option> <option value="12:30">12:30/13:15</option> <option value="13:30">13:30/14:15</option> <option value="14:15">14:15/15:00</option> <option value="15:15">15:15/16:00</option> <option value="16:00">16:00/16:45</option> <option value="16:55">16:55/17:40</option> <option value="17:40">17:40/18:25</option> </select> <select name="dsemana" onChange="get.submit();"> <option value="'.$ds.'">'.$ds.'</option> <option value="segunda-feira">Segunda-Feira</option> <option value="terca-feira">Terça-Feira</option> <option value="quarta-feira">Quarta-Feira</option> <option value="quinta-feira">Quinta-Feira</option> <option value="sexta-feira">Sexta-Feira</option> </select> <select name="turma" onChange="get.submit();"> <option value="'.$t.'">'.$t.'</option>'; while($myrow = mysql_fetch_array($tresultado)) { echo ' <option value='.$myrow['Turma'].'>'.$myrow['Turma'].'</option>'; } echo'</select> <select name="disciplinas" onChange="get.submit();"> <option value="'.$d.'">'.$d.'</option>'; while($myrow1 = mysql_fetch_array($dresultado)) { echo ' <option value='.$myrow1['CodDisci'].'>'.$myrow1['CodDisci'].'</option>'; } echo'</select></form>'; } else { header('Location: index.php'); } ?> Link to comment Share on other sites More sharing options...
KTachyon Posted June 10, 2012 at 09:21 PM Report Share #461840 Posted June 10, 2012 at 09:21 PM Estás a utilizar o $t antes de lhe atribuíres um valor... “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
Alpricc Posted June 10, 2012 at 09:37 PM Author Report Share #461842 Posted June 10, 2012 at 09:37 PM obrigado 🙂 por acaso consegui resolver isso antes de ver aqui a resposta xb outra coisa, da-me este erro "mysql_num_rows() expects parameter 1 to be resource, boolean given" normalmente de que é? porque aparece-me muitas vezes e eu resolvo e depois esqueço-me $codhor='SELECT Cod_horario FROM horario WHERE Hora=\''.$h.'\',CodDisci=\''.$d.'\',CodProf=\''.$_SESSION['cod'].'\',Turma=\''.$t.'\',DiaSemana=\''.$ds.'\''; $chresultado=mysql_query($codhor,$liga); $n_linhas=mysql_num_rows($chresultado); echo $n_linhas; ele devia retornar-me o valor 1 e da-me esse erro! Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 10, 2012 at 09:42 PM Report Share #461843 Posted June 10, 2012 at 09:42 PM (edited) porque deu erro no SQL coloca a seguinte linha logo após o query echo mysql_error(); PS : a separação de condições no where é com AND ou OR ... Edited June 10, 2012 at 09:43 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 10, 2012 at 09:45 PM Author Report Share #461844 Posted June 10, 2012 at 09:45 PM então tenho que por sempre AND AND AND? em vez de ","? Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted June 10, 2012 at 09:46 PM Report Share #461845 Posted June 10, 2012 at 09:46 PM depende da situação que pretendes ... ou AND ou OR ... caso tenhas dúvidas lê algo sobre lógica booleana IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Alpricc Posted June 10, 2012 at 09:47 PM Author Report Share #461846 Posted June 10, 2012 at 09:47 PM (edited) Pronto, essa parte ja esta a funcionar, so que agora nao me retorna o ECHO do MYROW2 mesmo que escolha os parametros certos -.- <?php session_start(); $liga=mysql_connect('localhost','root','') or die('Problemas na ligaÁ„o ao MYSQL'); if ($_SESSION['cod'] <> '') { $h=$_GET['hora']; $ds=$_GET['dsemana']; $t=$_GET['turma']; $d=$_GET['disci']; mysql_select_db('sistemadefaltas',$liga); $turmas = 'SELECT Turma FROM turmacurso'; $tresultado=mysql_query($turmas,$liga); $disciplinas='SELECT CodDisci FROM horario WHERE Turma=\''.$t.'\''; $dresultado=mysql_query($disciplinas,$liga); $codhor='SELECT Cod_horario FROM horario WHERE Hora=\''.$h.'\' AND CodDisci=\''.$d.'\' AND CodProf=\''.$_SESSION['cod'].'\' AND Turma=\''.$t.'\' AND DiaSemana=\''.$ds.'\''; $chresultado=mysql_query($codhor,$liga); $n_linhas=mysql_num_rows($chresultado); $myrow2 = mysql_fetch_array($chresultado); echo $myrow2['cod_horario']; echo'<form name="get" action="teste.php?" method="GET"> <select name="hora" onChange="get.submit();"> <option value="'.$h.'">'.$h.'</option> <option value="8:20">8:20/9:05</option> <option value="9:05">9:05/9:50</option> <option value="10:05">10:05/10:50</option> <option value="10:50">10:50/11:35</option> <option value="11:45">11:45/12:30</option> <option value="12:30">12:30/13:15</option> <option value="13:30">13:30/14:15</option> <option value="14:15">14:15/15:00</option> <option value="15:15">15:15/16:00</option> <option value="16:00">16:00/16:45</option> <option value="16:55">16:55/17:40</option> <option value="17:40">17:40/18:25</option> </select> <select name="dsemana" onChange="get.submit();"> <option value="'.$ds.'">'.$ds.'</option> <option value="Segunda-Feira">Segunda-Feira</option> <option value="terca-feira">Terça-Feira</option> <option value="quarta-feira">Quarta-Feira</option> <option value="quinta-feira">Quinta-Feira</option> <option value="sexta-feira">Sexta-Feira</option> </select> <select name="turma" onChange="get.submit();"> <option value="'.$t.'">'.$t.'</option>'; while($myrow = mysql_fetch_array($tresultado)) { echo ' <option value='.$myrow['Turma'].'>'.$myrow['Turma'].'</option>'; } echo'</select> <select name="disci" onChange="get.submit();"> <option value="'.$d.'">'.$d.'</option>'; while($myrow1 = mysql_fetch_array($dresultado)) {echo ' <option value='.$myrow1['CodDisci'].'>'.$myrow1['CodDisci'].'</option> <br />';} echo'</select></form>'; } else { header('Location: index.php'); } ?> Edited June 10, 2012 at 09:51 PM by Alpricc Link to comment Share on other sites More sharing options...
Rui Carlos Posted June 13, 2012 at 07:20 PM Report Share #462554 Posted June 13, 2012 at 07:20 PM Faz um echo do $n_linhas para ver se tens algum resultado. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Alpricc Posted June 14, 2012 at 09:01 PM Author Report Share #462937 Posted June 14, 2012 at 09:01 PM RESOLVIDO! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now