Jump to content

Recommended Posts

  • Replies 42
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted
<?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);
?>
Posted

<?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? :\

Posted

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í"

Posted

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?

Posted

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>
Posted

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);
Posted

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.

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.