← Desenvolvimento

if else = 31

Lida 4028 vezes

Offline

alexandremdn 
Membro
Mensagens 94 Gostos 2
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Nineth year Anniversary Level 5 Level 4 Avatar Eighth year Anniversary Seventh year Anniversary Windows User Super Combination Combination Topic Starter

Boas, estou aqui a maturar num if else simples mas está a dar este erro:

Parse error: syntax error, unexpected T_IF in /home/domain/public_html/Especialidades.htm on line 52

<?php
      include('themes/default/modules/'
         if (strpos($_SERVER['PHP_SELF'], 'index.htm')){  //esta é a linha 52
         echo 'header.htm';
         } else {
         echo 'header2.htm';
   }
   ?>

Alguém sabe onde está o erro?
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Não fechaste o include? em cima do if?
Offline

alexandremdn 
Membro
Mensagens 94 Gostos 2
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Nineth year Anniversary Level 5 Level 4 Avatar Eighth year Anniversary Seventh year Anniversary Windows User Super Combination Combination Topic Starter

O objectivo é:

Citar
<?php include('themes/default/modules/header.htm');?>

E quero alternar o ficheiro entre o header.htm e header2.htm dependendo da pagina em k estou:
Offline

alexandremdn 
Membro
Mensagens 94 Gostos 2
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Nineth year Anniversary Level 5 Level 4 Avatar Eighth year Anniversary Seventh year Anniversary Windows User Super Combination Combination Topic Starter

O objectivo é:

E quero alternar o ficheiro entre o header.htm e header2.htm dependendo da pagina em k estou:

Citar
<!-----------------------------------------------------------menu-------------------------------------------------------------------------->
   <?php include('themes/default/modules/menu.htm');?>
<!-----------------------------------------------------------header-------------------------------------------------------------------------->
   <?php include('themes/default/modules/'
         if (strpos($_SERVER['PHP_SELF'], 'index.htm'));{
         echo 'header.htm';
         } else {
         echo 'header2.htm';
   });
   ?>
Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Código: (php) [Seleccione]
<?php
         
if (strpos($_SERVER['PHP_SELF'], 'index.htm'));{
           include(
'themes/default/modules/header.htm');
         } else {
           include(
'themes/default/modules/header2.htm');
   });
   
?>

Eu nãi percebo nada de PHP, mas não é isto que queres?
Offline

Bruno Gaspar 
Membro
Mensagens 242 Gostos 1
Feedback +3

Troféus totais: 18
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 3 Level 2 Level 1 100 Posts 50 Posts 10 Posts

Eu nãi percebo nada de PHP, mas não é isto que queres?
Vai dar erro na mesma.

Código: (php) [Seleccione]
<?php
if (strpos($_SERVER['PHP_SELF'], 'index.htm'))
{
    include(
'themes/default/modules/header.htm');
} else {
    include(
'themes/default/modules/header2.htm');
}
?>


Outra maneira se o caminho dos ficheiros for o mesmo e só mudar o nome do ficheiro

Código: (php) [Seleccione]
<?php
if (strpos($_SERVER['PHP_SELF'], 'index.htm'))
{
    
$header 'header';
} else {
    
$header 'header2';
}
include(
"themes/default/modules/{$header}.htm");
?>


Podes também usar um Switch caso queiras apresentar mais "headers"
Offline

alexandremdn 
Membro
Mensagens 94 Gostos 2
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Nineth year Anniversary Level 5 Level 4 Avatar Eighth year Anniversary Seventh year Anniversary Windows User Super Combination Combination Topic Starter

É isso mesmo João... Obrigadão... Não me lembrei de fazer dessa forma... ta boa :)

dá-me é erro na mesma,  syntax error, unexpected T_ELSE
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

O que eu acho que procuras é o que o João Godinho escreveu em cima! :) Mas por uma questão de performance, se calhar o melhor é utilizares um switch.

Código: (php) [Seleccione]

<?php

switch ($_SERVER['PHP_SELF']) {

    case 
'index.php':
        include(
'themes/default/modules/headerindex.htm');
        break;

    case 
'contactos.php':
        include(
'themes/default/modules/headercontactos.htm');
        break;

    default:
       include(
'themes/default/modules/header.htm');

}
?>


Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Não consigo detectar nenhum erro, mas como disse não percebo nada de PHP. Usa a forma do Diogo, pois parece mesmo a melhor :P
Offline

alexandremdn 
Membro
Mensagens 94 Gostos 2
Feedback +2

Troféus totais: 25
Trófeus: (Ver todos)
Nineth year Anniversary Level 5 Level 4 Avatar Eighth year Anniversary Seventh year Anniversary Windows User Super Combination Combination Topic Starter

João Godinho e  Diogo Pinto e Bruno... Obrigadão. funcionou
Offline

Bruno Gaspar 
Membro
Mensagens 242 Gostos 1
Feedback +3

Troféus totais: 18
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Level 3 Level 2 Level 1 100 Posts 50 Posts 10 Posts

Não consigo detectar nenhum erro, mas como disse não percebo nada de PHP. Usa a forma do Diogo, pois parece mesmo a melhor :P

Citar
<?php
         if (strpos($_SERVER['PHP_SELF'], 'index.htm'));{ // aqui
           include('themes/default/modules/header.htm');
         } else {
           include('themes/default/modules/header2.htm');
   }); // aqui
   ?>

Portanto, estas a usar o ";" e ");" onde não podes e nem sequer faz sentido lol
Offline

Diogo Pinto 
Administrador
Mensagens 4400 Gostos 371
Feedback +4

Troféus totais: 37
Trófeus: (Ver todos)
Avatar Search Level 6 Linux User Mobile User Super Combination Combination Topic Starter 50 Poll Votes 10 Poll Votes

Não consigo detectar nenhum erro, mas como disse não percebo nada de PHP. Usa a forma do Diogo, pois parece mesmo a melhor :P

João os erros que tens é fechares as linhas com " ; " quando abres o if. Mas suponho que o OP saiba minimamente de PHP e tenha corrigido.

Aliás, o Bruno Gaspar corrigiu o teu código e removeu essas " ; ". ;) Mas a lógica está lá, é mesmo aquilo! :)
Offline

João Godinho 
Membro
Mensagens 1755 Gostos 2
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

Ah já vi, eu sabia que não podia usar ali mas não reparei que tinha metido :lol: