joninho Posted March 29, 2006 at 06:10 PM Report #20003 Posted March 29, 2006 at 06:10 PM bem, podiam-me diser o que está mal aqui? :\ se está mal.. :s <?php $level="1"; $menu = mysql_query(SELECT * FROM `Menu` WHERE $level); echo $menu; mysql_close($db); ?>
satanuke Posted March 29, 2006 at 06:43 PM Report #20005 Posted March 29, 2006 at 06:43 PM <?php $level="1"; $result = mysql_query(SELECT * FROM `Menu` WHERE $level); //vamos criar um ciclo para ir buscar cada posição do $result while($menu = mysql_fetch_array($result)){ print_r($menu); //isto é um array //se quiseres ir buscar um campo especifico basta print $menu['nome_do_campo']; } mysql_close($db); ?> tek.readers blog
Dabubble Posted March 29, 2006 at 06:51 PM Report #20006 Posted March 29, 2006 at 06:51 PM se nao me engano a query esta mal. Deveria ser: Select * from menu where level = 1 ou em php mysql_query(Select * from menu where level = $level,$db);
joninho Posted March 29, 2006 at 06:52 PM Author Report #20007 Posted March 29, 2006 at 06:52 PM ERRO!! :S lol Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jegd/public_html/index.php on line 158 www.jeg.addyour.net
joninho Posted March 29, 2006 at 06:54 PM Author Report #20009 Posted March 29, 2006 at 06:54 PM 157 //vamos criar um ciclo para ir buscar cada posição do $result 158 while($menu = mysql_fetch_array($result)){ 159 print_r($menu);
saramgsilva Posted March 29, 2006 at 07:30 PM Report #20020 Posted March 29, 2006 at 07:30 PM 157 //vamos criar um ciclo para ir buscar cada posição do $result 158 while($menu = mysql_fetch_array($result)){ 159 print_r($menu); se fores ver ao meu login nos tutis ves o erro... n é print_r é print... mas o while n esta bem...acho eu www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5
joninho Posted March 29, 2006 at 07:34 PM Author Report #20022 Posted March 29, 2006 at 07:34 PM <?php $level="1"; $result = mysql_query(SELECT * FROM `Menu` WHERE $level); //vamos criar um ciclo para ir buscar cada posição do $result while($menu = mysql_fetch_array($result)){ print_r($menu); //isto é um array //se quiseres ir buscar um campo especifico basta print $menu['nome_do_campo']; } mysql_close($db); ?> tofas eu copiei por aki, :S o while k problema tem? :\
saramgsilva Posted March 29, 2006 at 07:39 PM Report #20024 Posted March 29, 2006 at 07:39 PM print_r nao existe acho eu... mas nao tenho a certeza eu fazia...agora nao sei... while( list($pass)= @ mysql_fetch_row($resultado) ) { echo $pass; ..... } www.saramgsilva.com As minhas apps no WP7 Marketplace Youtube : Galinho - Windows Phone 7.5
pedrotuga Posted March 29, 2006 at 07:53 PM Report #20027 Posted March 29, 2006 at 07:53 PM Epa.. estao a divagar em varias direções... vê lá se isto funciona... olha as aspas que te esqueceste delas. <?php $query="Select * from menu where level=1"; $result=mysql_query($query); while($menu = mysql_fetch_array($result)){ echo $menu["coluna1"]; //usa antes o echo echo $menu["coluna3"]; echo $menu["coluna1"]; } ?> se tiveres muitas colunas podes fazer um loop pelo array $menu[n] enquanto n menor que mysql_num_cols($menu) Vê este exemplo escrito por mim nesta seccao agra há dias: O geshi permite clicar numa funcao e ir para a pagina desta no manual oficial do php, usa e abusa dessa funcionalidade 😄 Aqui vai o link: http://www.portugal-a-programar.pt/index.php?showtopic=1829 qq duvida "bota aí"
joninho Posted March 29, 2006 at 08:22 PM Author Report #20035 Posted March 29, 2006 at 08:22 PM dá sempre o mesmo erro: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jegd/public_html/index.php on line 158 :S k cena.. :\
pedrotuga Posted March 29, 2006 at 08:27 PM Report #20036 Posted March 29, 2006 at 08:27 PM dá sempre o mesmo erro: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/jegd/public_html/index.php on line 158 :S k cena.. :\ mmm... isso quer dizer que o a variável result não tem lá o resultado de um query... o que é impossivel com o código que eu te dei pois funciona para mim 😄 vamos cá resolver isto de forma metódica. 1.Experimenta a minha função para imprimir qq tabela... assim podes testar o teu sql, se resultar então o problema não é esse. 2.Tens a ligação à base de dados bem feita... testada?
Ped@ntilva Posted March 29, 2006 at 08:29 PM Report #20038 Posted March 29, 2006 at 08:29 PM acho que te estás a esquecer das aspas por isso tenta isto: $query="Select * from menu where level='1'";
joninho Posted March 29, 2006 at 08:33 PM Author Report #20039 Posted March 29, 2006 at 08:33 PM acho que te estás a esquecer das aspas por isso tenta isto: $query="Select * from menu where level='1'"; as aspas tao no sitio, opah a ligação ta direita senão dava erro a ligar ah bd.. :\ <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>::::::JoninhoAndGlorior:::::</title> <style type="text/css"> <!-- body,td,th { color: #0099FF; } body { background-color: #eeeeee; } a:link { color: #3399CC; text-decoration: underline; } a:visited { color: #3399CC; text-decoration: underline; } a:hover { color: #00ccFF; text-decoration: none; } a:active { color: #3399CC; text-decoration: underline; } .style1 {font-family: Geneva, Arial, Helvetica, sans-serif} .style3 { font-size: 12px; color: #000099; } --> </style></head> <body> <div align="center"> <table width="800" border="0" cellpadding="0" background="fundo.gif" cellspacing="0" bgcolor="#CCCCCC"> <!--DWLayoutTable--> <tr> <td width="6" height="132"></td> <td width="147"></td> <td width="483"></td> <td width="147"></td> <td width="17"></td> </tr> <tr> <td height="37"></td> <td valign="top" background="menuc.gif"><div align="center"> <p class="style1"><br> Menu</p> </div></td> <td rowspan="4" valign="top"><table width="100%" border="1px" bordercolor="#0099FF" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td rowspan="4" valign="top" bordercolor="#0099FF" border="1px"> <?php $db=mysql_connect ("localhost", " ", " ") or die ('Não é possivel aceder à Base de dados: ' . mysql_error()); mysql_select_db ("jegd_jeg"); $var = $_GET["action"]; switch($var){ case "portfolio": echo "PORTFOLIO"; break; case "sobre": echo "SOBRE"; break; case "register": ?> <form action="index.php?action=registando" method="post"> <span class="style3"> <label> <br> -Todos os campos são obrigatórios.<br> -O Username e a Password devem conter mais que 6 caracteres. </span> <div align="left"> <p><span class="style11">Nome</span>: <input type="text" name="nome" /> <span class="style11">E-mail</span>: <input type="text" name="email" /> </p> Username: <input type="text", name="username"/> </p> Password: <input type="password", name="password"/> </p> <p align="center"> <input name="submit2" type="submit" value="Registar",/> <input name="Reset" type="reset" value="Limpar"/> </p> <p> </label> </p> </div> </form> <?php break; case "registando": $nome= $_POST["nome"]; $email= $_POST["email"]; $password= $_POST["password"]; $username= $_POST["username"]; if ($nome!="" || $email!="" || $password!="" || $username!=""){ if($email!=="@"){ echo "o email tah incorrecto"; }else{ echo "tudo bem"; } echo "<p style=\"color:#00FF00\"> Dados Obtidos, </p> Nome: ".$nome."</br> email: ".$email."</br> Username: ".$username. "</br>Password: ".$password; }else{ echo "PRENCHE!!!"; ?> <META HTTP-EQUIV="Refresh" CONTENT="1; URL=index.php?action=register"> <?php }; break; default: echo "HOME"; break; } ?> </td> </tr> </table></td> <td valign="top" background="menuc.gif"> <div align="center"><br> <span class="style1">Estado</span> <br> </div></td> <td> </td> </tr> <tr> <td height="171"></td> <td valign="top" background="menum.gif" bgcolor="#dddddd"> <?php $level="1"; $query="Select * from menu where level=1"; $result=mysql_query($query); while($menu = mysql_fetch_array($result)){ echo $menu["coluna1"]; //usa antes o echo echo $menu["coluna3"]; echo $menu["coluna1"];} mysql_close($db); ?> <p> </p> <p> </p></td> <td valign="top" background="menum.gif"> <form name="form1" method="post" action="index.php?action=validarlogin"> <label>User: <br> <input type="text" name="Username"> <br> Pass:<br><input type="password" name="Password"> <input name="submit" type="submit" value="Login"> <a href="index.php?action=register">...register?</a><br> </label> </form></td> <td> </tr> <tr> <td height="37"></td> <td valign="top" background="menub.gif"><!--DWLayoutEmptyCell--> </td> <td valign="top" background="menub.gif"><!--DWLayoutEmptyCell--> </td> <td></td> </tr> <tr> <td height="33"></td> <td> </td> <td></td> <td></td> </tr> <tr> <td height="186"></td> <td> </td> <td> </td> <td></td> <td></td> </tr> </table> </div> </body> </html>
joninho Posted March 29, 2006 at 08:36 PM Author Report #20042 Posted March 29, 2006 at 08:36 PM opah e a tabela chama-se Menu e é assim: level int(1) menu text
Ped@ntilva Posted March 29, 2006 at 08:37 PM Report #20043 Posted March 29, 2006 at 08:37 PM Já tentas-te isto? $level="1"; $query="Select * from menu where level=1"; $result=mysql_query($query); while($menu = mysql_fetch_array($result)){ echo $menu[0]; //usa antes o echo echo $menu[1]; echo $menu[0];} mysql_close($db);
pedrotuga Posted March 29, 2006 at 08:44 PM Report #20047 Posted March 29, 2006 at 08:44 PM acho que te estás a esquecer das aspas por isso tenta isto: $query="Select * from menu where level='1'"; Acho que descobri... este código tem um erro... usa antes o meu código... estas a igualar um inteiro a uma string. Ja agora... aumenta o tamanho máximo do campo level... não gastas mais memória desde que mantenhas do tipo int.
Ped@ntilva Posted March 29, 2006 at 08:48 PM Report #20048 Posted March 29, 2006 at 08:48 PM Acho que descobri o teu prob. Tava mesmo à frente dos olhos... o erro que dá é no inicio do while... while($menu = mysql_fetch_row($result)){
joninho Posted March 29, 2006 at 08:57 PM Author Report #20052 Posted March 29, 2006 at 08:57 PM igual :S nao precebo o que é que falha :S
Ped@ntilva Posted March 29, 2006 at 08:58 PM Report #20053 Posted March 29, 2006 at 08:58 PM vou experimentar esse codigo e ja te digo...
pedrotuga Posted March 29, 2006 at 09:05 PM Report #20055 Posted March 29, 2006 at 09:05 PM yaps confirma falta-te selecionar a base de dados.. só te ligas ao servidor de base de dados mas depois nao escolhes a db Usa esta linha: mysql_select_db($dbname)OR DIE("impossivel ligar a base de dados"); logo apos ao mysql_connect(); Claro que tens k por em $dbnamo o nome da bd que vais usar.
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